public static async Task SendKeyPress(WindowsVirtualKey key, int holdTime = 50) { SetGameWindowFocus(); await SendKeypressForALittleWhile(key, holdTime); Application.Current.MainWindow.Activate(); }
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)); } }
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); }
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); } }
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 } } }); }
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)); }
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); }
public KeyStateInfo(WindowsVirtualKey vkey, bool ispressed, bool istoggled) { _vkey = vkey; _isPressed = ispressed; _isToggled = istoggled; }
private uint ConvertKey(WindowsVirtualKey winKey) { //TODO - Some keys can only be implemented via keysyms return((uint)KeyTranslator.WindowsToLinux(winKey)); }
public FunctionHotkey(WindowsVirtualKey key, HotkeyModifiers mods, Hotkeyfunction function) : base(key, mods) { Function = function; }
public Hotkey(WindowsVirtualKey key, HotkeyModifiers mods) { Key = key; Modifiers = mods; }
public ClientHotkey(WindowsVirtualKey key, HotkeyModifiers mods, Guid targetClient) : base(key, mods) { TargetClient = targetClient; }