コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="aHidEvent"></param>
        public void OnHidEvent(object aSender, Hid.Event aHidEvent)
        {
            HidListener.LogInfo("\n" + aHidEvent.ToString());

            if (aHidEvent.IsRepeat)
            {
                HidListener.LogInfo("HID: Repeat");
            }

            _actions = null;
            _actions = new List <MediaPortal.InputDevices.HidUsageAction.ConditionalAction>();
            HidUsageAction usageAction;

            // Check if we have mappings for this usage ID (page/collection).
            if (_usageActions.TryGetValue(aHidEvent.UsageId, out usageAction))
            {
                //Alright we do handle this usage ID
                //Try mapping actions to each of our usage
                if (aHidEvent.IsGeneric)
                {
                    foreach (ushort usage in aHidEvent.Usages)
                    {
                        HidListener.LogInfo("HID: try mapping usage 0x{0}", usage.ToString("X4"));
                        HidUsageAction.ConditionalAction action = usageAction.GetAction(usage.ToString(), aHidEvent.IsBackground, aHidEvent.IsRepeat, aHidEvent.HasModifierShift, aHidEvent.HasModifierControl, aHidEvent.HasModifierAlt, aHidEvent.HasModifierWindows);
                        _actions.Add(action);
                        if (_shouldRaiseAction)
                        {
                            usageAction.ExecuteActionIfNeeded(action);
                        }
                    }

                    //Do some extra checks if our device is a gamepad
                    if (aHidEvent.Device != null && aHidEvent.Device.IsGamePad)
                    {
                        //Check if dpad needs to be handled too
                        HidListener.LogInfo("HID: try mapping dpad {0}", aHidEvent.GetDirectionPadState());
                        const int KDPadButtonOffset             = 1000; //This is our magic dpad button offset. Should be good enough as it leaves us with 998 genuine buttons.
                        ushort    dpadFakeUsage                 = (ushort)(KDPadButtonOffset + (int)aHidEvent.GetDirectionPadState());
                        HidUsageAction.ConditionalAction action = usageAction.GetAction(dpadFakeUsage.ToString(), aHidEvent.IsBackground, aHidEvent.IsRepeat, aHidEvent.HasModifierShift, aHidEvent.HasModifierControl, aHidEvent.HasModifierAlt, aHidEvent.HasModifierWindows);
                        _actions.Add(action);
                        if (_shouldRaiseAction)
                        {
                            usageAction.ExecuteActionIfNeeded(action);
                        }
                    }
                }
                else if (aHidEvent.IsKeyboard && aHidEvent.IsButtonDown && !GUIWindowManager.NeedsTextInput)
                {
                    //Keyboard handling
                    ushort virtualKey = aHidEvent.RawInput.keyboard.VKey;
                    HidListener.LogInfo("HID: try mapping virtual code 0x{0}", virtualKey.ToString("X4"));
                    HidUsageAction.ConditionalAction action = usageAction.GetAction(virtualKey.ToString(), aHidEvent.IsBackground, aHidEvent.IsRepeat, aHidEvent.HasModifierShift, aHidEvent.HasModifierControl, aHidEvent.HasModifierAlt, aHidEvent.HasModifierWindows);
                    _actions.Add(action);
                    if (_shouldRaiseAction)
                    {
                        usageAction.ExecuteActionIfNeeded(action);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="aHidEvent"></param>
        private void PrivateCopy(Hid.Event aHidEvent)
        {
            //Copy for scan
            UsagePage       = aHidEvent.UsagePage;
            UsageCollection = aHidEvent.UsageCollection;
            IsGeneric       = aHidEvent.IsGeneric;
            IsKeyboard      = aHidEvent.IsKeyboard;
            IsMouse         = aHidEvent.IsMouse;

            if (IsGeneric)
            {
                if (aHidEvent.Usages.Count > 0)
                {
                    Usage     = aHidEvent.Usages[0];
                    UsageName = aHidEvent.UsageName(0);
                }

                Key                = Keys.None;
                HasModifierAlt     = false;
                HasModifierControl = false;
                HasModifierShift   = false;
                HasModifierWindows = false;
            }
            else if (IsKeyboard)
            {
                Usage              = 0;
                Key                = aHidEvent.VirtualKey;
                HasModifierAlt     = aHidEvent.HasModifierAlt;
                HasModifierControl = aHidEvent.HasModifierControl;
                HasModifierShift   = aHidEvent.HasModifierShift;
                HasModifierWindows = aHidEvent.HasModifierWindows;
            }
        }
コード例 #3
0
ファイル: EventHid.cs プロジェクト: Slion/CIC
        /// <summary>
        /// TODO: Optionally save the device name to make it specific to a device.
        /// </summary>
        /// <param name="aHidEvent"></param>
        protected void PrivateCopy(Hid.Event aHidEvent)
        {
            HidEvent = aHidEvent;

            //Copy for scan
            Usages             = aHidEvent.Usages;
            UsagePage          = aHidEvent.UsagePage;
            UsageCollection    = aHidEvent.UsageCollection;
            Device.CurrentItem = aHidEvent.Device?.InstancePath ?? "";
            CheckDeviceExistance();
            IsGeneric  = aHidEvent.IsGeneric;
            IsKeyboard = aHidEvent.IsKeyboard;
            IsMouse    = aHidEvent.IsMouse;
            IsGamePad  = aHidEvent.Device?.IsGamePad ?? false;
            IsJoystick = aHidEvent.Device?.IsJoystick ?? false;

            if (IsGeneric)
            {
                if (IsGamePad || IsJoystick)
                {
                    if (aHidEvent.Usages.Count > 0)
                    {
                        Usage     = aHidEvent.Usages[0];
                        UsageName = "Button " + Usage;
                    }
                }
                else
                {
                    // We were assuming this is a remote control
                    if (aHidEvent.Usages.Count > 0)
                    {
                        Usage     = aHidEvent.Usages[0];
                        UsageName = aHidEvent.UsageName(0);
                    }
                }

                Key                = Keys.None;
                HasModifierAlt     = false;
                HasModifierControl = false;
                HasModifierShift   = false;
                HasModifierWindows = false;
            }
            else if (IsKeyboard)
            {
                Usage              = 0;
                Key                = aHidEvent.VirtualKey;
                HasModifierAlt     = aHidEvent.HasModifierAlt;
                HasModifierControl = aHidEvent.HasModifierControl;
                HasModifierShift   = aHidEvent.HasModifierShift;
                HasModifierWindows = aHidEvent.HasModifierWindows;
            }
        }
コード例 #4
0
ファイル: HidHandler.cs プロジェクト: brownard/MediaPortal-1
        /// <summary>
        ///
        /// </summary>
        /// <param name="aHidEvent"></param>
        public void OnHidEvent(object aSender, Hid.Event aHidEvent)
        {
            if (aHidEvent.IsRepeat)
            {
                HidListener.LogInfo("HID: Repeat");
            }

            _actions = null;
            _actions = new List <MediaPortal.InputDevices.HidUsageAction.ConditionalAction>();
            HidUsageAction usageAction;

            if (_usageActions.TryGetValue(aHidEvent.UsageId, out usageAction))
            {
                //Alright we do handle this usage ID
                //Try mapping actions to each of our usage
                foreach (ushort usage in aHidEvent.Usages)
                {
                    HidListener.LogInfo("HID: try mapping usage {0}", usage.ToString("X4"));
                    _actions.Add(usageAction.GetAction(usage.ToString(), aHidEvent.IsBackground, aHidEvent.IsRepeat));
                    if (_shouldRaiseAction)
                    {
                        usageAction.MapAction(usage, aHidEvent.IsBackground, aHidEvent.IsRepeat);
                    }
                }

                //Do some extra checks if our device is a gamepad
                if (aHidEvent.Device.IsGamePad)
                {
                    //Check if dpad needs to be handled too
                    HidListener.LogInfo("HID: try mapping dpad {0}", aHidEvent.GetDirectionPadState());
                    const int KDPadButtonOffset = 1000; //This is our magic dpad button offset. Should be good enough as it leaves us with 998 genuine buttons.
                    ushort    dpadFakeUsage     = (ushort)(KDPadButtonOffset + (int)aHidEvent.GetDirectionPadState());
                    _actions.Add(usageAction.GetAction(dpadFakeUsage.ToString(), aHidEvent.IsBackground, aHidEvent.IsRepeat));
                    if (_shouldRaiseAction)
                    {
                        usageAction.MapAction(dpadFakeUsage, aHidEvent.IsBackground, aHidEvent.IsRepeat);
                    }
                }
            }
        }
コード例 #5
0
        private void OnHidEvent(object sender, SharpLib.Hid.Event hidEvent)
        {
            try
            {
                if (hidEvent.IsButtonDown)
                {
                    if (hidEvent.IsGeneric)
                    {
                        var id = hidEvent.Usages.FirstOrDefault();
                        if (hidEvent.UsagePageEnum == UsagePage.WindowsMediaCenterRemoteControl && !_currentCodes[REMOTE_INPUT_TYPE].Contains(id.ToString()))
                        {
                            _currentCodes[REMOTE_INPUT_TYPE].Add(id.ToString());
                        }
                        if (hidEvent.UsagePageEnum == UsagePage.Consumer && !_currentCodes[CONSUMER_INPUT_TYPE].Contains(id.ToString()))
                        {
                            _currentCodes[CONSUMER_INPUT_TYPE].Add(id.ToString());
                        }
                    }
                    else if (hidEvent.IsKeyboard)
                    {
                        int key = (int)hidEvent.VirtualKey;
                        if (!_currentCodes[KEYBOARD_INPUT_TYPE].Contains(key.ToString()))
                        {
                            _currentCodes[KEYBOARD_INPUT_TYPE].Add(key.ToString());
                        }
                    }
                    _resetTimer.Enabled = true;
                }
                if (hidEvent.IsButtonUp)
                {
                    if (hidEvent.IsGeneric)
                    {
                        var id = hidEvent.Usages.FirstOrDefault();
                        if (hidEvent.UsagePageEnum == UsagePage.WindowsMediaCenterRemoteControl)
                        {
                            if (IsCombinationMatch(REMOTE_INPUT_TYPE))
                            {
                                OnStartRequest?.Invoke(this, EventArgs.Empty);
                            }

                            if (_currentCodes[REMOTE_INPUT_TYPE].Contains(id.ToString()))
                            {
                                _currentCodes[REMOTE_INPUT_TYPE].Remove(id.ToString());
                            }
                        }
                        else if (hidEvent.UsagePageEnum == UsagePage.Consumer)
                        {
                            if (IsCombinationMatch(CONSUMER_INPUT_TYPE))
                            {
                                OnStartRequest?.Invoke(this, EventArgs.Empty);
                            }

                            if (_currentCodes[CONSUMER_INPUT_TYPE].Contains(id.ToString()))
                            {
                                _currentCodes[CONSUMER_INPUT_TYPE].Remove(id.ToString());
                            }
                        }
                    }
                    else if (hidEvent.IsKeyboard)
                    {
                        if (IsCombinationMatch(KEYBOARD_INPUT_TYPE))
                        {
                            OnStartRequest?.Invoke(this, EventArgs.Empty);
                        }

                        int key = (int)hidEvent.VirtualKey;
                        if (_currentCodes[KEYBOARD_INPUT_TYPE].Contains(key.ToString()))
                        {
                            _currentCodes[KEYBOARD_INPUT_TYPE].Remove(key.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error("HID event failed", ex);
            }
        }
コード例 #6
0
ファイル: EventHid.cs プロジェクト: Slion/CIC
 /// <summary>
 /// Used to capture incoming HID events
 /// </summary>
 /// <param name="aHidEvent"></param>
 public void Copy(Hid.Event aHidEvent)
 {
     PrivateCopy(aHidEvent);
     //We need the key up/down too here
     IsKeyUp = aHidEvent.IsButtonUp;
 }