Пример #1
0
        internal void OnKeyInfoReceived(Events.KeyInfo keyInfo)
        {
            // TODO: ensure that keyInfo._resourceId always equals 1
            System.Diagnostics.Debug.Assert(keyInfo.ResourceId == 1);
            if (keyInfo.KeyCode == (long)KeyCode.Tivo)
            {
                // special processing for tivo key
                // this key can't be sent by the device, so it must be simulated.
                // currently using this as timer callback
                lock (_actions)
                {
                    object   obj;
                    Delegate action;
                    if (_actionObjects.TryGetValue(keyInfo.RawCode, out obj))
                    {
                        _actionObjects.Remove(keyInfo.RawCode);
                    }
                    if (_actions.TryGetValue(keyInfo.RawCode, out action))
                    {
                        _actions.Remove(keyInfo.RawCode);
                        action.DynamicInvoke(obj);
                    }
                }
            }
            else
            {
                EventHandler <KeyEventArgs> handler;
                KeyEventArgs args = new KeyEventArgs((KeyCode)keyInfo.KeyCode, keyInfo.RawCode);
                switch (keyInfo.KeyAction)
                {
                case Events.KeyAction.Press:
                    if (ActiveView != null)
                    {
                        ActiveView.OnKeyDown(args);
                    }
                    if (!args.Handled)
                    {
                        handler = KeyDown;
                        if (handler != null)
                        {
                            handler(this, args);
                        }
                    }
                    args.Handled = false;
                    if (ActiveView != null)
                    {
                        ActiveView.OnKeyPress(args);
                    }
                    if (!args.Handled)
                    {
                        handler = KeyPress;
                        if (handler != null)
                        {
                            handler(this, args);
                        }
                    }
                    break;

                case Events.KeyAction.Repeat:
                    if (ActiveView != null)
                    {
                        ActiveView.OnKeyPress(args);
                    }
                    if (!args.Handled)
                    {
                        handler = KeyPress;
                        if (handler != null)
                        {
                            handler(this, args);
                        }
                    }
                    break;

                case Events.KeyAction.Release:
                    if (ActiveView != null)
                    {
                        ActiveView.OnKeyUp(args);
                    }
                    if (!args.Handled)
                    {
                        handler = KeyUp;
                        if (handler != null)
                        {
                            handler(this, args);
                        }
                    }
                    break;
                }
            }
        }