示例#1
0
        public static async Task SendKeyPress(WindowsVirtualKey key, int holdTime = 50)
        {
            SetGameWindowFocus();
            await SendKeypressForALittleWhile(key, holdTime);

            Application.Current.MainWindow.Activate();
        }
示例#2
0
        private void HandleKeyEvent(XKeyEvent evt)
        {
            bool pressed = evt.type == XEventName.KeyPress;

            if (Settings.DEBUG_PRINTINPUTKEYS)
            {
                ISLogger.Write("DEBUG: KEY {0} (raw {1})", (LinuxKeyCode)evt.keycode, evt.keycode);
            }

            //Raise a hotkey pressed event instead of an input event
            if (pressed)
            {
                if (CheckForHotkey(evt))
                {
                    return;
                }
            }

            WindowsVirtualKey key = KeyTranslator.LinuxToWindows((LinuxKeyCode)evt.keycode);


            if (pressed)
            {
                OnInputReceived(new ISInputData(ISInputCode.IS_KEYDOWN, (short)key, 0));
            }
            else
            {
                OnInputReceived(new ISInputData(ISInputCode.IS_KEYUP, (short)key, 0));
            }
        }
示例#3
0
        private async Task ExecuteMove(Move move)
        {
            WindowsVirtualKey virtualKey = WindowsVirtualKey.Up;

            switch (move.direction)
            {
            case Direction.Up:
                virtualKey = WindowsVirtualKey.Up;
                break;

            case Direction.Down:
                virtualKey = WindowsVirtualKey.Down;
                break;

            case Direction.Left:
                virtualKey = WindowsVirtualKey.Left;
                break;

            case Direction.Right:
                virtualKey = WindowsVirtualKey.Right;
                break;

            case Direction.None:
                return;
            }

            var distance   = Math.Max(Math.Abs(move.start.x - move.end.x), Math.Abs(move.start.y - move.end.y));
            var timeToHold = (30 * distance) + MainWindow.Delay;

            await PinvokeHelpers.SendKeyPress(virtualKey, timeToHold);
        }
示例#4
0
 public static LinuxKeyCode WindowsToLinux(WindowsVirtualKey key)
 {
     try
     {
         return((LinuxKeyCode)Enum.Parse(typeof(LinuxKeyCode), key.ToString()));
     }catch (Exception ex)
     {
         ISLogger.Write("Failed to translate windows key {0}: {1}", key, ex.Message);
         return(0);
     }
 }
示例#5
0
        private static async Task SendKeypressForALittleWhile(WindowsVirtualKey key, int holdTime)
        {
            var hwnd = GetAdrenalineWindowHandle();

            // absolutely insane usage of async here john, fix it up
            var t = Task.Delay(holdTime);

            while (!t.IsCompleted)
            {
                SendMessage(hwnd.ToInt32(), WM_KEYDOWN, (int)key, 1);
            }

            await t;
        }
 public INPUT toINPUT(WindowsVirtualKey key, KeyFlags flag)
 {
     return(new INPUT()
     {
         Type = 1,
         Data = new MOUSEKEYBDHARDWAREINPUT()
         {
             Keyboard = new KEYBDINPUT()
             {
                 ExtraInfo = GetMessageExtraInfo(),
                 Flags = (uint)flag,
                 Time = 0,
                 Scan = 0,
                 Vk = (ushort)key
             }
         }
     });
 }
示例#7
0
        private static Hotkey FromSettingsString(string hkStr)
        {
            string[] args = hkStr.Split(':');

            if (args.Length == 0)
            {
                return(null);
            }

            if (!WindowsVirtualKey.TryParse(typeof(WindowsVirtualKey), args[0], true, out var keyObj))
            {
                return(null);
            }

            WindowsVirtualKey key  = (WindowsVirtualKey)keyObj;
            HotkeyModifiers   mods = 0;

            for (int i = 1; i < args.Length; i++)
            {
                string modStr = args[i];

                if (modStr == HotkeyModifiers.Alt.ToString())
                {
                    mods |= HotkeyModifiers.Alt;
                }
                else if (modStr == HotkeyModifiers.Ctrl.ToString())
                {
                    mods |= HotkeyModifiers.Ctrl;
                }
                else if (modStr == HotkeyModifiers.Shift.ToString())
                {
                    mods |= HotkeyModifiers.Shift;
                }
            }

            return(new Hotkey(key, mods));
        }
示例#8
0
        public static KeyStateInfo GetKeyState(WindowsVirtualKey vkey)
        {
            short keyState = GetKeyState((int)vkey);
            byte[] bits = BitConverter.GetBytes(keyState);
            bool toggled = bits[0] > 0, pressed = bits[1] > 0;

            return new KeyStateInfo(vkey, pressed, toggled);
        }
示例#9
0
 public KeyStateInfo(WindowsVirtualKey vkey,
                 bool ispressed,
                 bool istoggled)
 {
     _vkey = vkey;
     _isPressed = ispressed;
     _isToggled = istoggled;
 }
示例#10
0
 private uint ConvertKey(WindowsVirtualKey winKey)
 {
     //TODO - Some keys can only be implemented via keysyms
     return((uint)KeyTranslator.WindowsToLinux(winKey));
 }
示例#11
0
 public FunctionHotkey(WindowsVirtualKey key, HotkeyModifiers mods, Hotkeyfunction function) : base(key, mods)
 {
     Function = function;
 }
示例#12
0
 public Hotkey(WindowsVirtualKey key, HotkeyModifiers mods)
 {
     Key       = key;
     Modifiers = mods;
 }
示例#13
0
 public ClientHotkey(WindowsVirtualKey key, HotkeyModifiers mods, Guid targetClient) : base(key, mods)
 {
     TargetClient = targetClient;
 }