private static bool IsRepeatKey(Win32.WindowHook.KBDLLHOOKSTRUCT hookStruct) { int vk = (int)(hookStruct.vkCode & 0xFF); lock (pressedKeys) { bool keyIsPressed = pressedKeys[vk] == 0x80; if (Win32.WindowHook.LLKHF.UP != (hookStruct.flags & Win32.WindowHook.LLKHF.UP)) { if (keyIsPressed) { return(true); } else { pressedKeys[vk] = 0x80; } } else { if (!keyIsPressed) { return(true); } else { pressedKeys[vk] = (byte)(Win32.IsToggled((Win32.VK)vk) ? 1 : 0); } } } return(false); }
private static bool OnKeyboardInputReceived(Win32.WM wParam, Win32.WindowHook.KBDLLHOOKSTRUCT hookStruct) { // fix for 'key repeat' windows feature if (pressedKeys.Contains((byte)(hookStruct.vkCode & 0xFF))) { return(false); } // and ignore "global desktop keys" Mubox.Configuration.KeySetting globalKeySetting = null; if (Mubox.Configuration.MuboxConfigSection.Default.Keys.TryGetKeySetting((Win32.VK)hookStruct.vkCode, out globalKeySetting) && (globalKeySetting.SendToDesktop)) { return(false); } // filter repeated keys, we don't rebroadcast these if (IsRepeatKey(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.Teams.ActiveTeam != null) { Mubox.Configuration.ClientSettings activeClient = Mubox.Configuration.MuboxConfigSection.Default.Teams.ActiveTeam.ActiveClient; if (activeClient != null) { activeClient.Keys.TryGetKeySetting((Win32.VK)keyboardInputEventArgs.VK, out keySetting); } if (keySetting != null) { keyboardInputEventArgs.VK = (uint)keySetting.OutputKey; keyboardInputEventArgs.CAS = keySetting.OutputModifiers; } } } OnKeyboardInputReceivedInternal(keyboardInputEventArgs); return(keyboardInputEventArgs.Handled); } return(false); }