Пример #1
0
        /// <summary>
        /// <para>Updates 'pressed keys', returns true if pressed keys was updated.</para>
        /// </summary>
        /// <param name="hookStruct"></param>
        /// <returns>True if key state has/is changed due to this event.</returns>
        private static bool UpdatePressedKeys(WinAPI.WindowHook.KBDLLHOOKSTRUCT hookStruct)
        {
            var result = false;

            if (WinAPI.WindowHook.LLKHF.UP != (hookStruct.flags & WinAPI.WindowHook.LLKHF.UP))
            {
                if (!IsKeyPressed(hookStruct.vkCode))
                {
                    result = true;
                    pressedKeys[(int)hookStruct.vkCode] = true;
                }
            }
            else
            {
                if (IsKeyPressed(hookStruct.vkCode))
                {
                    result = true;
                    pressedKeys[(int)hookStruct.vkCode] = false;
                }
            }
            return(result);
        }
Пример #2
0
        private static bool OnKeyboardInputReceived(WinAPI.WM wParam, WinAPI.WindowHook.KBDLLHOOKSTRUCT hookStruct)
        {
            // ignore injected input
            if (hookStruct.flags.HasFlag(WinAPI.WindowHook.LLKHF.INJECTED))
            {
                return(false);
            }

            // coerce specialized left/right shift-state to generalized shift-state
            if (MuboxConfigSection.Default.Profiles.ActiveProfile.EnableCASFix)
            {
                switch ((WinAPI.VK)hookStruct.vkCode)
                {
                case WinAPI.VK.LeftShift:
                case WinAPI.VK.RightShift:
                    hookStruct.vkCode = WinAPI.VK.Shift;
                    break;

                case WinAPI.VK.LeftMenu:
                case WinAPI.VK.RightMenu:
                    hookStruct.vkCode = WinAPI.VK.Menu;
                    break;

                case WinAPI.VK.LeftControl:
                case WinAPI.VK.RightControl:
                    hookStruct.vkCode = WinAPI.VK.Control;
                    break;
                }
            }

            // ignore "global desktop keys"
            Mubox.Configuration.KeySetting globalKeySetting = null;
            if (Mubox.Configuration.MuboxConfigSection.Default.Profiles.ActiveProfile.Keys.TryGetKeySetting((WinAPI.VK)hookStruct.vkCode, out globalKeySetting) && (globalKeySetting.SendToDesktop))
            {
                return(false);
            }

            // update pressed keys
            if (!UpdatePressedKeys(hookStruct) && Mubox.Configuration.MuboxConfigSection.Default.IsCaptureEnabled && !Mubox.Configuration.MuboxConfigSection.Default.DisableRepeatKeyFiltering)
            {
                return(true);
            }

            // count
            if (Performance.IsPerformanceEnabled)
            {
                KeyboardInputPerformance.Count(Convert.ToInt64(hookStruct.time));
            }

            // handle high-level
            if (KeyboardInputReceived != null)
            {
                KeyboardInput keyboardInputEventArgs = KeyboardInput.CreateFrom(wParam, hookStruct);
                {
                    Mubox.Configuration.KeySetting keySetting = globalKeySetting;
                    if (Mubox.Configuration.MuboxConfigSection.Default.Profiles.ActiveProfile != null)
                    {
                        Mubox.Configuration.ClientSettings activeClient = Mubox.Configuration.MuboxConfigSection.Default.Profiles.ActiveProfile.ActiveClient;
                        if (activeClient != null)
                        {
                            activeClient.Keys.TryGetKeySetting((WinAPI.VK)keyboardInputEventArgs.VK, out keySetting);
                        }
                        if (keySetting != null)
                        {
                            keyboardInputEventArgs.VK  = keySetting.OutputKey;
                            keyboardInputEventArgs.CAS = keySetting.OutputModifiers;
                        }
                    }
                }
                OnKeyboardInputReceivedInternal(keyboardInputEventArgs);
                return(keyboardInputEventArgs.Handled);
            }

            return(false);
        }