Beispiel #1
0
 private static void SetStateVirtual(Key key, bool state)
 {
     if (key.IsStateless())
     {
         return;
     }
     if (state)
     {
         DownKeysVirtual.Add(key);
     }
     else
     {
         DownKeysVirtual.Remove(key);
     }
 }
Beispiel #2
0
        public static bool DeviceInput(IDeviceInput input)
        {
            // Mouse move is handled here to reduce performance impact due to its high frequency
            if (input.Key == Key.MouseMove)
            {
                if (input.Injected)
                {
                    return(false);
                }
                MoveEvent?.Invoke();
                LastMouseAction = Time.Now;
                return(IsLocked || IsMouseLocked || IsMouseMoveLocked);
            }

            if (input.Key.IsUnknown())
            {
                return(false);
            }
            var key = !StatelessNumpad || !input.Key.IsNumpad() ? input.Key : MapNumpad(input.Key);

            // Deal with injected input
            if (input.Injected && (!key.IsMedia() || (uint)input.ExtraInfo == pid))
            {
                if (!key.IsStateless())
                {
                    if (input.State)
                    {
                        DownKeysVirtual.Add(key);
                    }
                    else
                    {
                        DownKeysVirtual.Remove(key);
                    }
                }

                return(false);
            }

            // Record key state if it has changed (ignore auto-repeat presses)
            if (input.State != IsDown(key))
            {
                if (!key.IsStateless())
                {
                    SetState(key, input.State);
                }
                History.Push(new KeyState(key, input.State));
                GlobalIDs[key] = ++CurrentGlobalID;
            }

            // Invoke special key event subscriptions
            InputEvent?.Invoke(key, input.State);

            // Check lock state
            bool locked = IsLocked || IsAllKeysLocked || (key.IsMouse() ? IsMouseLocked : IsKeyboardLocked) || IsLockedKey(key);
            bool blocked;

            // Update idle info
            if (key.IsMouse())
            {
                LastMouseAction = Time.Now;
            }
            else
            {
                LastKeyboardAction = Time.Now;
            }

            // If hotkey is running tell it that the key has been released
            if (!input.State && HotkeyManager.CurrentHotkeys.ContainsKey(key))
            {
                blocked = HotkeyManager.KeyUp(key);
            }

            // Block key if locked
            else if (locked)
            {
                return(true);
            }

            // Hotkey for that key is already running
            else if (HotkeyManager.CurrentHotkeys.ContainsKey(key))
            {
                blocked = HotkeyManager.IsBlocked(key);
            }

            // Pass key event to hotkey manager
            else if (input.State)
            {
                blocked = HotkeyManager.KeyDown(key);
            }
            else
            {
                blocked = HotkeyManager.KeyUp(key);
            }

            if (!blocked)
            {
                SetStateVirtual(key, input.State);
            }
            return(blocked);
        }