public static void AsyncHoldKey(VirtualKeyCode keycode) { if (InputSimulator.asyncHoldThread == null || !InputSimulator.asyncHoldThread.IsAlive) { InputSimulator.asyncHoldThread = new System.Threading.Thread( new System.Threading.ThreadStart(() => { while (InputSimulator.currentAsyncHoldKeys.Count > 0) { lock (InputSimulator.currentAsyncHoldKeys) { foreach (VirtualKeyCode iter in InputSimulator.currentAsyncHoldKeys) { Console.WriteLine(iter); WindowsInput.InputSimulator.SimulateKeyDown(iter); } } System.Threading.Thread.Sleep(10); } })); InputSimulator.asyncHoldThread.IsBackground = true; InputSimulator.asyncHoldThread.Start(); } currentAsyncHoldKeys.Add(keycode); }
public static void DoKeyPress(VirtualKeyCode aKey) { InputSimulator.SimulateKeyDown(aKey); Thread.Sleep(200); InputSimulator.SimulateKeyUp(aKey); Thread.Sleep(200); }
public static void UpKey(VirtualKeyCode keyCode) { if (Status.isKeyEnabled && InputSimulator.IsKeyDown(keyCode)) { InputSimulator.SimulateKeyUp(keyCode); } }
public ModifierKey(VirtualKeyCode key, params VirtualKeyCode[] additional) { _key = key; _additional = additional; if(_additional == null) _additional = new VirtualKeyCode[0]; }
public static Command GenerateCommand(InstructionData instruction) { VirtualKeyCode[] keys=new VirtualKeyCode[Values.GetLength(0)]; Values.CopyTo(keys, 0); switch (instruction.commandType) { case InstructionData_CommandType.JOYSTICKAXIS: return new Command(new JoystickCommandData(0,(JoystickDataType)instruction.axis,(short)instruction.value)); case InstructionData_CommandType.JOYSTICKBUTTON_PRESS: return new Command(new JoystickCommandData(0, JoystickDataType.BUTTON_PRESS, 0, instruction.value)); case InstructionData_CommandType.JOYSTICKBUTTON_HOLD: return new Command(new JoystickCommandData(0, JoystickDataType.BUTTON_HOLD, 0, instruction.value)); case InstructionData_CommandType.JOYSTICKBUTTON_RELEASE: return new Command(new JoystickCommandData(0, JoystickDataType.BUTTON_RELEASE, 0, instruction.value)); case InstructionData_CommandType.KEYBOARD_PRESS: return new Command(new KeyboardCommandData(keys[instruction.value], KeyboardCommandType.PRESS, instruction.control, instruction.shift)); case InstructionData_CommandType.KEYBOARD_HOLD: return new Command(new KeyboardCommandData(keys[instruction.value], KeyboardCommandType.HOLD, instruction.control, instruction.shift)); case InstructionData_CommandType.KEYBOARD_RELEASE: return new Command(new KeyboardCommandData(keys[instruction.value], KeyboardCommandType.RELEASE, instruction.control, instruction.shift)); } return null; }
public static void SimulateKeyPress(VirtualKeyCode keyCode) { var down = new Input(); down.Type = (UInt32)InputType.KEYBOARD; down.Data.Keyboard = new KeybdInput { Vk = (UInt16) keyCode, Scan = 0, Flags = 0, Time = 0, ExtraInfo = IntPtr.Zero }; var up = new Input(); up.Type = (UInt32)InputType.KEYBOARD; up.Data.Keyboard = new KeybdInput { Vk = (UInt16) keyCode, Scan = 0, Flags = (UInt32) KeyboardFlag.KEYUP, Time = 0, ExtraInfo = IntPtr.Zero }; var inputList = new Input[2]; inputList[0] = down; inputList[1] = up; var numberOfSuccessfulSimulatedInputs = User32.SendInput(2, inputList, Marshal.SizeOf(typeof(Input))); if (numberOfSuccessfulSimulatedInputs == 0) throw new Exception(string.Format("The key press simulation for {0} was not successful.", keyCode)); }
public static void PressKey(VirtualKeyCode keyCode) { if (Status.isKeyEnabled) { InputSimulator.SimulateKeyPress(keyCode); } }
/// <summary> /// Эмулирует действие 'нажать и держать' над кнопкой. /// </summary> /// <param name="keyCode"> /// Ключ целевой кнопки. /// </param> public IKeyboard KeyDown(VirtualKeyCode keyCode) { this.logger.Info("Key down '{0}'", keyCode.ToString()); this.keyboardSimulator.KeyDown(keyCode); Thread.Sleep(250); return this; }
public KeyboardCommandData(VirtualKeyCode key, KeyboardCommandType type, bool control = false, bool shift = false) { this.key = key; this.type = type; this.control = control; this.shift = shift; }
public void Set(VirtualKeyCode key, KeyState keyState) { if(_modifierKeyState.ContainsKey(key)) _modifierKeyState[key] = keyState; else _modifierKeyState.Add(key, keyState); }
public static void DoBuff(VirtualKeyCode aKey, bool aSelf) { Point OldMousePos = MouseGetPos();; if (aSelf) CenterMouse(); DoSkill(aKey); if (aSelf) MouseMove(OldMousePos); }
public ShiftSensitiveKey(VirtualKeyCode keyCode, string normal, string modified, string displayText) { _keyCode = keyCode; _normal = normal; _modified = modified; _displayText = displayText; Display = !string.IsNullOrEmpty(_displayText) ? _displayText : _normal; }
private void AddKeyInput(VirtualKeyCode keyCode, bool isKeyUp) { INPUT input = new INPUT(); input.Type = InputType.InputKeyboard; input.Data.Keyboard = new KEYBDINPUT(); input.Data.Keyboard.wVk = keyCode; if (isKeyUp) input.Data.Keyboard.dwFlags = KeyboardEventFlags.KEYEVENTF_KEYUP; InputList.Add(input); }
public static void AsyncReleaseKey(VirtualKeyCode keycode) { lock (InputSimulator.currentAsyncHoldKeys) { InputSimulator.SimulateKeyUp(keycode); InputSimulator.currentAsyncHoldKeys.RemoveAll(key => key.Equals(keycode)); } }
public MultiCharacterKey(VirtualKeyCode keyCode, IList<string> keyDisplays) : base(keyCode) { if (keyDisplays == null) throw new ArgumentNullException("keyDisplays"); if (keyDisplays.Count <= 0) throw new ArgumentException("Please provide a list of one or more keyDisplays", "keyDisplays"); KeyDisplays = keyDisplays; DisplayName = keyDisplays[0]; }
public VirtualKey(VirtualKeyCode virtualKey, string displayText, List<int> characters, bool isAffectedByCapsLock) { _virtualKey = virtualKey; _characters = characters; _isAffectedByCapsLock = isAffectedByCapsLock; _displayText = displayText; for (var x = 0; x < characters.Count; x++) { var character = default(char); var value = characters[x]; if (value == Definitions.WCH_DEAD) { character = ' '; } else if (value == Definitions.WCH_LGTR) { character = ' '; } else if (value == Definitions.WCH_NONE) { character = ' '; } else { character = (char)value; } switch (x) { case 0: characterBase = character; break; case 1: characterShift = character; break; case 2: characterAltGraphics = character; break; case 3: characterControl = character; break; case 4: characterShiftControl = character; break; case 5: characterShiftAltGraphics = character; break; } } Display = GetDisplayValue(false, false); }
/// <summary> /// Calls the Win32 SendInput method with a KeyDown and KeyUp message in the same input sequence in order to simulate a Key PRESS. /// </summary> /// <param name="keyCode">The <see cref="VirtualKeyCode"/> to press</param> public void KeyPress(VirtualKeyCode keyCode) { var inputList = new InputBuilder() .AddKeyDown(keyCode) .AddKeyUp(keyCode) .ToArray(); SendSimulatedInput(inputList); }
public static void PressKey(VirtualKeyCode S) { if (WindowHandle == null) { Console.WriteLine("Cant Send Keypress to Null Window"); return; } InputSimulator.SimulateKeyPress(S); Console.WriteLine("Sent Key"); }
public void KeyUp(VirtualKeyCode virtualKeyCode) { try { Log.DebugFormat("Simulating key up: {0}", virtualKeyCode); inputSimulator.Keyboard.KeyUp(virtualKeyCode); } catch (Exception exception) { PublishError(this, exception); } }
public void SendMessage(VirtualKeyCode key, VirtualKeyCode? modifier = null) { SetForegroundWindow(hWndLast); if (modifier != null) { InputSimulator.SimulateModifiedKeyStroke((VirtualKeyCode)modifier, key); return; } InputSimulator.SimulateKeyPress(key); }
public override void Parse(EvtItem item) { //Modifiers = item.modifier; Code = ParseCode(item.key); if (item.modifier != null && item.modifier.Length > 0) { foreach (var i in item.modifier) { var vc = ParseCode(i); Modifiers.Add(vc); } } }
public void AddKeyPressModifiers(VirtualKeyCode keyCode, params VirtualKeyCode[] modifiers) { foreach (VirtualKeyCode modifier in modifiers) { AddKeyDown(modifier); } AddKeyPress(keyCode); foreach (VirtualKeyCode modifier in modifiers) { AddKeyUp(modifier); } }
public KeyAction(VirtualKeyCode key) { this._key = key; }
/// <summary> /// Determines whether the toggling key is toggled on (in-effect) or not by calling the <see cref="NativeMethods.GetKeyState"/> function. (See: http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx) /// </summary> /// <param name="keyCode">The <see cref="VirtualKeyCode"/> for the key.</param> /// <returns> /// <c>true</c> if the toggling key is toggled on (in-effect); otherwise, <c>false</c>. /// </returns> /// <remarks> /// The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information. /// An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated. /// To retrieve state information for all the virtual keys, use the GetKeyboardState function. /// An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys. /// VK_LSHIFT /// VK_RSHIFT /// VK_LCONTROL /// VK_RCONTROL /// VK_LMENU /// VK_RMENU /// /// These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. /// </remarks> public bool IsTogglingKeyInEffect(VirtualKeyCode keyCode) { Int16 result = NativeMethods.GetKeyState((UInt16)keyCode); return((result & 0x01) == 0x01); }
static public MotionResult KeyboardPress( this IHostToScript sanderling, VirtualKeyCode key) => sanderling?.KeyboardPressCombined(new[] { key });
static public bool IsAltKey(this VirtualKeyCode key) => VirtualKeyCode.MENU == key || VirtualKeyCode.LMENU == key || VirtualKeyCode.RMENU == key;
/// <summary> /// Adds a key press to the list of <see cref="INPUT"/> messages which is equivalent to a key down followed by a key up. /// </summary> /// <param name="keyCode">The <see cref="VirtualKeyCode"/>.</param> /// <returns>This <see cref="InputBuilder"/> instance.</returns> public InputBuilder AddKeyPress(VirtualKeyCode keyCode) { AddKeyDown(keyCode); AddKeyUp(keyCode); return(this); }
public VirtualKey(VirtualKeyCode virtualKey, string displayText, List <int> characters, bool isAffectedByCapsLock) { _virtualKey = virtualKey; _characters = characters; _isAffectedByCapsLock = isAffectedByCapsLock; _displayText = displayText; for (var x = 0; x < characters.Count; x++) { var character = default(char); var value = characters[x]; if (value == Definitions.WCH_DEAD) { character = ' '; } else if (value == Definitions.WCH_LGTR) { character = ' '; } else if (value == Definitions.WCH_NONE) { character = ' '; } else { character = (char)value; } switch (x) { case 0: characterBase = character; break; case 1: characterShift = character; break; case 2: characterAltGraphics = character; break; case 3: characterControl = character; break; case 4: characterShiftControl = character; break; case 5: characterShiftAltGraphics = character; break; } } Display = GetDisplayValue(false, false); }
public static bool ExecuteAbility(string ability, string args, bool qc, Dota2Core core, bool forceCancel) { Dota2GSI.Nodes.Abilities abilities = core.Abilities(); VirtualKeyCode key = VirtualKeyCode.VK_S; if (abilities == null) { return(false); } if (abilities.Count == 4) { if (ability == "Q") { key = VirtualKeyCode.VK_Q; if (!abilities[0].CanCast && (core.mainForm.Cancel() || forceCancel)) { return(false); } } if (ability == "W") { key = VirtualKeyCode.VK_W; if (!abilities[1].CanCast && (core.mainForm.Cancel() || forceCancel)) { return(false); } } if (ability == "E") { key = VirtualKeyCode.VK_E; if (!abilities[2].CanCast && (core.mainForm.Cancel() || forceCancel)) { return(false); } } if (ability == "R") { key = VirtualKeyCode.VK_R; if (!abilities[3].CanCast && (core.mainForm.Cancel() || forceCancel)) { return(false); } } } if (abilities.Count == 5) { if (ability == "Q") { key = VirtualKeyCode.VK_Q; if (!abilities[0].CanCast && (core.mainForm.Cancel() || forceCancel)) { return(false); } } if (ability == "W") { key = VirtualKeyCode.VK_W; if (!abilities[1].CanCast && (core.mainForm.Cancel() || forceCancel)) { return(false); } } if (ability == "E") { key = VirtualKeyCode.VK_E; if (!abilities[2].CanCast && (core.mainForm.Cancel() || forceCancel)) { return(false); } } if (ability == "D") { key = VirtualKeyCode.VK_D; if (!abilities[3].CanCast && (core.mainForm.Cancel() || forceCancel)) { return(false); } } if (ability == "R") { key = VirtualKeyCode.VK_R; if (!abilities[4].CanCast && (core.mainForm.Cancel() || forceCancel)) { return(false); } } } if (abilities.Count == 6) { if (ability == "Q") { key = VirtualKeyCode.VK_Q; if (!abilities[0].CanCast && (core.mainForm.Cancel() || forceCancel)) { return(false); } } if (ability == "W") { key = VirtualKeyCode.VK_W; if (!abilities[1].CanCast && (core.mainForm.Cancel() || forceCancel)) { return(false); } } if (ability == "E") { key = VirtualKeyCode.VK_E; if (!abilities[2].CanCast && (core.mainForm.Cancel() || forceCancel)) { return(false); } } if (ability == "D") { key = VirtualKeyCode.VK_D; if (!abilities[3].CanCast && (core.mainForm.Cancel() || forceCancel)) { return(false); } } if (ability == "F") { key = VirtualKeyCode.VK_F; if (!abilities[4].CanCast && (core.mainForm.Cancel() || forceCancel)) { return(false); } } if (ability == "R") { key = VirtualKeyCode.VK_R; if (!abilities[5].CanCast && (core.mainForm.Cancel() || forceCancel)) { return(false); } } } if (ability == "Z") { key = VirtualKeyCode.VK_Z; } if (ability == "X") { key = VirtualKeyCode.VK_X; } if (ability == "C") { key = VirtualKeyCode.VK_C; } if (ability == "V") { key = VirtualKeyCode.VK_V; } if (ability == "B") { key = VirtualKeyCode.VK_B; } if (ability == "N") { key = VirtualKeyCode.VK_N; } if (ability == "A") { key = VirtualKeyCode.VK_A; } if (core.mainForm.SelectHero() && forceCancel) { KBMHelper.SelectHero(VirtualKeyCode.F1); } if (args == "SELF") { if (qc) { KBMHelper.PressAltKey(key); } else { KBMHelper.PressKey(key); KBMHelper.PressKey(key); } } else { KBMHelper.PressKey(key); if (!qc) { KBMHelper.LClick(); } } return(true); }
/// <summary> /// Performs a modified keystroke where there are multiple modifiers and one key like CTRL-ALT-C where CTRL and ALT are the modifierKeys and C is the key. /// The flow is Modifiers KEYDOWN in order, Key PRESS, Modifiers KEYUP in reverse order. /// </summary> /// <param name="modifierKeyCodes">The list of modifier keys</param> /// <param name="keyCode">The key to simulate</param> public static void SimulateModifiedKeyStroke(IEnumerable<VirtualKeyCode> modifierKeyCodes, VirtualKeyCode keyCode) { if (modifierKeyCodes != null) modifierKeyCodes.ToList().ForEach(x => SimulateKeyDown(x)); SimulateKeyPress(keyCode); if (modifierKeyCodes != null) modifierKeyCodes.Reverse().ToList().ForEach(x => SimulateKeyUp(x)); }
/// <summary> /// Calls the Win32 SendInput method to simulate a Key UP. /// </summary> /// <param name="keyCode">The VirtualKeyCode to lift up</param> public static void SimulateKeyUp(VirtualKeyCode keyCode) { var up = new InputSimulatorDefines(); up.Type = (UInt32)InputType.KEYBOARD; up.Data.Keyboard = new KEYBDINPUT(); up.Data.Keyboard.Vk = (UInt16)keyCode; up.Data.Keyboard.Scan = 0; up.Data.Keyboard.Flags = (UInt32)KeyboardFlag.KEYUP; up.Data.Keyboard.Time = 0; up.Data.Keyboard.ExtraInfo = IntPtr.Zero; InputSimulatorDefines[] inputList = new InputSimulatorDefines[1]; inputList[0] = up; var numberOfSuccessfulSimulatedInputs = SendInput(1, inputList, Marshal.SizeOf(typeof(InputSimulatorDefines))); if (numberOfSuccessfulSimulatedInputs == 0) throw new Exception(string.Format("The key up simulation for {0} was not successful.", keyCode)); }
/// <summary> /// Determines whether the physical key is up or down at the time the function is called regardless of whether the application thread has read the keyboard event from the message pump by calling the <see cref="NativeMethods.GetAsyncKeyState"/> function. (See: http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx) /// </summary> /// <param name="keyCode">The <see cref="VirtualKeyCode"/> for the key.</param> /// <returns> /// <c>true</c> if the key is up; otherwise, <c>false</c>. /// </returns> /// <remarks> /// The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by calling /// Copy CodeGetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons have been swapped. /// /// Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application. The behavior of the least significant bit of the return value is retained strictly for compatibility with 16-bit Windows applications (which are non-preemptive) and should not be relied upon. /// /// You can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the vKey parameter. This gives the state of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. /// /// Windows NT/2000/XP: You can use the following virtual-key code constants as values for vKey to distinguish between the left and right instances of those keys. /// /// Code Meaning /// VK_LSHIFT Left-shift key. /// VK_RSHIFT Right-shift key. /// VK_LCONTROL Left-control key. /// VK_RCONTROL Right-control key. /// VK_LMENU Left-menu key. /// VK_RMENU Right-menu key. /// /// These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. /// </remarks> public bool IsHardwareKeyUp(VirtualKeyCode keyCode) { return !IsHardwareKeyDown(keyCode); }
/// <summary> /// Determines whether the physical key is up or down at the time the function is called regardless of whether the application thread has read the keyboard event from the message pump by calling the <see cref="NativeMethods.GetAsyncKeyState"/> function. (See: http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx) /// </summary> /// <param name="keyCode">The <see cref="VirtualKeyCode"/> for the key.</param> /// <returns> /// <c>true</c> if the key is down; otherwise, <c>false</c>. /// </returns> /// <remarks> /// The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by calling /// Copy CodeGetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons have been swapped. /// /// Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application. The behavior of the least significant bit of the return value is retained strictly for compatibility with 16-bit Windows applications (which are non-preemptive) and should not be relied upon. /// /// You can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the vKey parameter. This gives the state of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. /// /// Windows NT/2000/XP: You can use the following virtual-key code constants as values for vKey to distinguish between the left and right instances of those keys. /// /// Code Meaning /// VK_LSHIFT Left-shift key. /// VK_RSHIFT Right-shift key. /// VK_LCONTROL Left-control key. /// VK_RCONTROL Right-control key. /// VK_LMENU Left-menu key. /// VK_RMENU Right-menu key. /// /// These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. /// </remarks> public bool IsHardwareKeyDown(VirtualKeyCode keyCode) { var result = NativeMethods.GetAsyncKeyState((UInt16)keyCode); return(result < 0); }
/// <summary> /// Determines whether the specified key is up or downby calling the <see cref="NativeMethods.GetKeyState"/> function. (See: http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx) /// </summary> /// <param name="keyCode">The <see cref="VirtualKeyCode"/> for the key.</param> /// <returns> /// <c>true</c> if the key is up; otherwise, <c>false</c>. /// </returns> /// <remarks> /// The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information. /// An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated. /// To retrieve state information for all the virtual keys, use the GetKeyboardState function. /// An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for Bthe nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys. /// VK_LSHIFT /// VK_RSHIFT /// VK_LCONTROL /// VK_RCONTROL /// VK_LMENU /// VK_RMENU /// /// These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. /// </remarks> public bool IsKeyUp(VirtualKeyCode keyCode) { return(!IsKeyDown(keyCode)); }
/// <summary> /// Determines whether the specified key is up or down by calling the GetKeyState function. (See: http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx) /// </summary> /// <param name="keyCode">The <see cref="VirtualKeyCode"/> for the key.</param> /// <returns> /// <c>true</c> if the key is down; otherwise, <c>false</c>. /// </returns> /// <remarks> /// The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information. /// An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated. /// To retrieve state information for all the virtual keys, use the GetKeyboardState function. /// An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for Bthe nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys. /// VK_LSHIFT /// VK_RSHIFT /// VK_LCONTROL /// VK_RCONTROL /// VK_LMENU /// VK_RMENU /// /// These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. /// </remarks> public bool IsKeyDown(VirtualKeyCode keyCode) { Int16 result = NativeMethods.GetKeyState((UInt16)keyCode); return(result < 0); }
public VirtualKeyCodeHolder(VirtualKeyCode virtualKeyCode) { _virtualKeyCode = virtualKeyCode; UpdateModifierExtendedMembers(); }
public static bool ExecuteItem(string item, string args, bool qc, Dota2Core core, bool forceCancel) { Dota2GSI.Nodes.Items items = core.Items(); VirtualKeyCode key = VirtualKeyCode.VK_S; if (items == null) { return(false); } int index = -1; if (!items.InventoryContains(item)) { return(false); } index = items.InventoryIndexOf(item); if (index == -1) { return(false); } if ((index > 5 || !items.GetInventoryAt(index).CanCast) && (core.mainForm.Cancel() || forceCancel)) { return(false); } if (index == 0) { key = VirtualKeyCode.VK_Z; } if (index == 1) { key = VirtualKeyCode.VK_X; } if (index == 2) { key = VirtualKeyCode.VK_C; } if (index == 3) { key = VirtualKeyCode.VK_V; } if (index == 4) { key = VirtualKeyCode.VK_B; } if (index == 5) { key = VirtualKeyCode.VK_N; } if (core.mainForm.SelectHero() && forceCancel) { KBMHelper.SelectHero(VirtualKeyCode.F1); } if (args == "SELF") { if (qc) { KBMHelper.PressAltKey(key); } else { KBMHelper.PressKey(key); KBMHelper.PressKey(key); } } else { KBMHelper.PressKey(key); if (!qc) { KBMHelper.LClick(); } } return(true); }
/// <summary> /// Determines whether a key is up or down at the time the function is called by calling the GetAsyncKeyState function. (See: http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx) /// </summary> /// <param name="keyCode">The key code.</param> /// <returns> /// <c>true</c> if the key is down; otherwise, <c>false</c>. /// </returns> /// <remarks> /// The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by calling /// Copy CodeGetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons have been swapped. /// /// Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application. The behavior of the least significant bit of the return value is retained strictly for compatibility with 16-bit Windows applications (which are non-preemptive) and should not be relied upon. /// /// You can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the vKey parameter. This gives the state of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. /// /// Windows NT/2000/XP: You can use the following virtual-key code constants as values for vKey to distinguish between the left and right instances of those keys. /// /// Code Meaning /// VK_LSHIFT Left-shift key. /// VK_RSHIFT Right-shift key. /// VK_LCONTROL Left-control key. /// VK_RCONTROL Right-control key. /// VK_LMENU Left-menu key. /// VK_RMENU Right-menu key. /// /// These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. /// </remarks> public static bool IsKeyDownAsync(VirtualKeyCode keyCode) { Int16 result = GetAsyncKeyState((UInt16)keyCode); return (result < 0); }
public KeyPressedEventArgs(VirtualKeyCode Key, bool down = true, bool up = false) { KeyCode = Key; KeyDown = down; KeyUp = up; }
public override void Method() { VirtualKeyCode keyCode = (VirtualKeyCode)(Keys)Enum.Parse(typeof(Keys), Parameters[0], true); InputHelpers.SendKeyUp(keyCode); }
/// <summary> /// Gets the hotkey. /// </summary> /// <param name="timeout">The timeout.</param> /// <returns></returns> /// <exception cref="InvalidOperationException">The " + nameof(InputManager) + /// " needs to be initialized before it can execute this method.</exception> public VirtualKeyCode GetHotkey(int timeout = -1) { if (!IsInitialized) { throw new InvalidOperationException("The " + nameof(InputManager) + " needs to be initialized before it can execute this method."); } var threadLock = new object(); VirtualKeyCode hotkey = VirtualKeyCode.Invalid; LowLevelMouseHook.MouseEventHandler mouseEventHandler = (VirtualKeyCode key, KeyState state, int x, int y) => { if (state != KeyState.Down) { return; } hotkey = key; if (!Monitor.TryEnter(threadLock)) { return; } // someone else has the lock Monitor.PulseAll(threadLock); Monitor.Exit(threadLock); }; LowLevelKeyboardHook.KeyboardEventHandler keyboardEventHandler = (VirtualKeyCode key, KeyState state) => { if (state != KeyState.Down) { return; } hotkey = key; if (!Monitor.TryEnter(threadLock)) { return; } // someone else has the lock Monitor.PulseAll(threadLock); Monitor.Exit(threadLock); }; this.OnMouseEvent += mouseEventHandler; this.OnKeyboardEvent += keyboardEventHandler; bool result; Monitor.Enter(threadLock); if (timeout < 0) { Monitor.Wait(threadLock); result = true; } else { result = Monitor.Wait(threadLock, timeout); } this.OnMouseEvent -= mouseEventHandler; this.OnKeyboardEvent -= keyboardEventHandler; return(hotkey); }
public bool IsHardwareKeyUp(VirtualKeyCode keyCode) { return(true); }
static public bool IsCtrlKey(this VirtualKeyCode key) => VirtualKeyCode.CONTROL == key || VirtualKeyCode.LCONTROL == key || VirtualKeyCode.RCONTROL == key;
public void UpdateKeyStatus(VirtualKeyCode keyCode, KeyStatus status) { KeyActionCharacteristicWrapper.NotifyKeyStatus(keyCode, status); }
static public bool WindowPostMessageKeyUp(this IHostToScript host, VirtualKeyCode key, IntPtr lParam = default(IntPtr)) => host.WindowPostMessage(0x101, (IntPtr)key, lParam);
public Key(VirtualKeyCode code, KeyStates state) { _state = state; _code = code; }
public bool IsKeyDown(VirtualKeyCode keyCode) { return(false); }
public GestureDetector(KinectSensor kinectSensor, string dataBase, string gestureName, int refID, VirtualKeyCode key, float thresh) { if (kinectSensor == null) { throw new ArgumentNullException("kinectSensor"); } gestureDatabase = dataBase; dataName = gestureName; //pressKey = key; keyPress = key; threshHold = thresh; referenceID = refID; // create the vgb source. The associated body tracking ID will be set when a valid body frame arrives from the sensor. this.vgbFrameSource = new VisualGestureBuilderFrameSource(kinectSensor, 0); this.vgbFrameSource.TrackingIdLost += this.Source_TrackingIdLost; // open the reader for the vgb frames this.vgbFrameReader = this.vgbFrameSource.OpenReader(); if (this.vgbFrameReader != null) { //this.vgbFrameReader.IsPaused = true; this.vgbFrameReader.FrameArrived += this.Reader_GestureFrameArrived; } // load the 'Seated' gesture from the gesture database using (VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(this.gestureDatabase)) { // we could load all available gestures in the database with a call to vgbFrameSource.AddGestures(database.AvailableGestures), // but for this program, we only want to track one discrete gesture from the database, so we'll load it by name foreach (Gesture gesture in database.AvailableGestures) { if (gesture.Name.Equals(this.dataName)) { this.vgbFrameSource.AddGesture(gesture); } } } }
public bool IsKeyUp(VirtualKeyCode keyCode) { return(true); }
public bool IsTogglingKeyInEffect(VirtualKeyCode keyCode) { return(false); }
/// <summary> /// Simulates a simple modified keystroke like CTRL-C where CTRL is the modifierKey and C is the key. /// The flow is Modifier KeyDown, Key Press, Modifier KeyUp. /// </summary> /// <param name="modifierKeyCode">The modifier key</param> /// <param name="keyCode">The key to simulate</param> public IKeyboardSimulator ModifiedKeyStroke(VirtualKeyCode modifierKeyCode, VirtualKeyCode keyCode) { ModifiedKeyStroke(new[] { modifierKeyCode }, new[] { keyCode }); return(this); }
public InstantaneousModifierKey(string displayName, VirtualKeyCode keyCode) : base(keyCode) { DisplayName = displayName; }
public CtrlAltShiftAndCaseSensitiveKey(VirtualKeyCode keyCode, IList<string> keyDisplays) : base(keyCode, keyDisplays) { }
/// <summary> /// Simulates a modified keystroke where there are multiple modifiers and one key like CTRL-ALT-C where CTRL and ALT are the modifierKeys and C is the key. /// The flow is Modifiers KeyDown in order, Key Press, Modifiers KeyUp in reverse order. /// </summary> /// <param name="modifierKeyCodes">The list of modifier keys</param> /// <param name="keyCode">The key to simulate</param> public IKeyboardSimulator ModifiedKeyStroke(IEnumerable <VirtualKeyCode> modifierKeyCodes, VirtualKeyCode keyCode) { ModifiedKeyStroke(modifierKeyCodes, new[] { keyCode }); return(this); }
/// <summary> /// Performs a simple modified keystroke like CTRL-C where CTRL is the modifierKey and C is the key. /// The flow is Modifier KEYDOWN, Key PRESS, Modifier KEYUP. /// </summary> /// <param name="modifierKeyCode">The modifier key</param> /// <param name="keyCode">The key to simulate</param> public static void SimulateModifiedKeyStroke(VirtualKeyCode modifierKeyCode, VirtualKeyCode keyCode) { SimulateKeyDown(modifierKeyCode); SimulateKeyPress(keyCode); SimulateKeyUp(modifierKeyCode); }
/// <summary> /// Simulates a modified keystroke where there is one modifier and multiple keys like CTRL-K-C where CTRL is the modifierKey and K and C are the keys. /// The flow is Modifier KeyDown, Keys Press in order, Modifier KeyUp. /// </summary> /// <param name="modifierKey">The modifier key</param> /// <param name="keyCodes">The list of keys to simulate</param> public IKeyboardSimulator ModifiedKeyStroke(VirtualKeyCode modifierKey, IEnumerable <VirtualKeyCode> keyCodes) { ModifiedKeyStroke(new[] { modifierKey }, keyCodes); return(this); }
/// <summary> /// Performs a modified keystroke where there is one modifier and multiple keys like CTRL-K-C where CTRL is the modifierKey and K and C are the keys. /// The flow is Modifier KEYDOWN, Keys PRESS in order, Modifier KEYUP. /// </summary> /// <param name="modifierKey">The modifier key</param> /// <param name="keyCodes">The list of keys to simulate</param> public static void SimulateModifiedKeyStroke(VirtualKeyCode modifierKey, IEnumerable<VirtualKeyCode> keyCodes) { SimulateKeyDown(modifierKey); if (keyCodes != null) keyCodes.ToList().ForEach(x => SimulateKeyPress(x)); SimulateKeyUp(modifierKey); }
/// <summary> /// /// </summary> /// <param name="keyCode"></param> /// <param name="displayName"></param> public VirtualKey(VirtualKeyCode keyCode, string displayName) { DisplayName = displayName; KeyCode = keyCode; }
/// <summary> /// Determines whether the toggling key is toggled on (in-effect) or not by calling the GetKeyState function. (See: http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx) /// </summary> /// <param name="keyCode">The <see cref="VirtualKeyCode"/> for the key.</param> /// <returns> /// <c>true</c> if the toggling key is toggled on (in-effect); otherwise, <c>false</c>. /// </returns> /// <remarks> /// The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information. /// An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated. /// To retrieve state information for all the virtual keys, use the GetKeyboardState function. /// An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys. /// VK_LSHIFT /// VK_RSHIFT /// VK_LCONTROL /// VK_RCONTROL /// VK_LMENU /// VK_RMENU /// /// These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. /// </remarks> public static bool IsTogglingKeyInEffect(VirtualKeyCode keyCode) { Int16 result = GetKeyState((UInt16)keyCode); return (result & 0x01) == 0x01; }
/// <summary> /// /// </summary> /// <param name="keyCode"></param> public VirtualKey(VirtualKeyCode keyCode) { KeyCode = keyCode; }