public static bool IsKeyPressed(VirtualKeyStates testKey) { bool keyPressed = false; short result = GetKeyState(testKey); switch (result) { case 0: // Not pressed and not toggled on. keyPressed = false; break; case 1: // Not pressed, but toggled on keyPressed = false; break; default: // Pressed (and may be toggled on) keyPressed = true; break; } return(keyPressed); }
public static bool IsKeyPressed(VirtualKeyStates testKey) { bool keyPressed = false; short result = GetKeyState(testKey); switch (result) { case 0: // Not pressed and not toggled on. keyPressed = false; break; case 1: // Not pressed, but toggled on keyPressed = true; break; default: // Pressed (and may be toggled on) keyPressed = true; break; } return keyPressed; }
public static int GetKeyState(VirtualKeyStates testKey) { byte[] keys = new byte[256]; //Get pressed keys if (!NativeMethods.GetKeyboardState(keys)) { int err = Marshal.GetLastWin32Error(); throw new Win32Exception(err); } Convert.ToBoolean(GetAsyncKeyState(Keys.ControlKey) & 0x8000); for (int i = 0; i < 256; i++) { byte key = keys[i]; //Logical 'and' so we can drop the low-order bit for toggled keys, else that key will appear with the value 1! if ((key & 0x80) != 0) { //This is just for a short demo, you may want this to return //multiple keys! return((int)key); } } return(-1); }
public void ListenTo(VirtualKeyStates keyStates) { if (!KeyListeners.Contains(keyStates)) { KeyListeners.Add(keyStates); } }
public bool IsPressed(VirtualKeyStates key) { bool isPressed = KeyState.IsPressed(key); // return(isPressed); }
public bool IsKeyDown(VirtualKeyStates key) { /* * if (null != CurrentKeys) * return CurrentKeys.Contains(key); * return false; */ if (null != CurrentKeys) { return(CurrentKeys.Contains(key)); } return(false); }
public bool IsNewKeyDown(VirtualKeyStates key) { /* * if (null != CurrentKeys) * return CurrentKeys.Contains(key); * return false; */ if (null != ProcessedKeys) { return(ProcessedKeys.NewKeysDown.Contains(key)); } return(false); }
public static bool IsKeyPressed(VirtualKeyStates nVirtKey) { switch (GetKeyState(nVirtKey)) { case 0: // Not pressed and not toggled on. return(false); case 1: // Not pressed, but toggled on return(false); default: // Pressed (and may be toggled on) return(true); } }
bool IsKeyPressed(VirtualKeyStates testKey) { bool keyPressed = false; short result = GetKeyState(testKey); switch (result) { case 0: keyPressed = false; break; case 1: keyPressed = false; break; default: keyPressed = true; break; } return(keyPressed); }
public static bool IsKeyToggled(VirtualKeyStates key) { return(Convert.ToBoolean(NativeMethods.GetKeyState(VirtualKeyStates.VK_LBUTTON) & KEY_TOGGLED)); }
internal static extern int GetKeyState(VirtualKeyStates keyState);
public static extern ushort GetAsyncKeyState(VirtualKeyStates nVirtKey);
protected bool IsPressed(VirtualKeyStates key) { return(KeyState.IsPressed(key)); }
/// <summary> /// Determina si una tecla especÃfica está presionada /// </summary> /// <param name="keyCode">código de la tecla</param> /// <returns>True si la tecla está siendo presionado, false de lo contrerio</returns> public bool IsHardwareKeyDown(VirtualKeyStates keyCode) { var result = GetAsyncKeyState((UInt16)keyCode); return(result < 0); }
public static bool IsKeyDown(VirtualKeyStates nVirtKey) { return(Convert.ToBoolean(GetKeyState(nVirtKey) & KeyPressed)); }
public static bool IsKeyDown(VirtualKeyStates nVirtKey) { return Convert.ToBoolean(GetKeyState(nVirtKey) & KeyPressed); }
public static void MSendMessage(IntPtr hWnd, UInt32 msg, VirtualKeyStates key, int num) { SendMessage(hWnd, msg, (IntPtr)key, (IntPtr)num); }
public static void ControlSendMessage(IntPtr hWnd, VirtualKeyStates key, bool shift, bool ctrl) { hWnd = MWin.FindWindowEx(hWnd, IntPtr.Zero, "Edit", ""); if (shift == true) { //send shift down SendMessage(hWnd, WM_KEYDOWN, (IntPtr)VirtualKeyStates.VK_SHIFT, (IntPtr)0); //send key down SendMessage(hWnd, WM_KEYDOWN, (IntPtr)key, (IntPtr)0); //sleep 50ms Thread.Sleep(50); //send key up SendMessage(hWnd, WM_KEYUP, (IntPtr)key, (IntPtr)0); //send shift up SendMessage(hWnd, WM_KEYUP, (IntPtr)VirtualKeyStates.VK_SHIFT, (IntPtr)0); } else if (ctrl == true) { //send shift down SendMessage(hWnd, WM_KEYDOWN, (IntPtr)VirtualKeyStates.VK_CONTROL, (IntPtr)0); //send key down SendMessage(hWnd, WM_KEYDOWN, (IntPtr)key, (IntPtr)0); //sleep 50ms Thread.Sleep(50); //send key up SendMessage(hWnd, WM_KEYUP, (IntPtr)key, (IntPtr)0); //send shift up SendMessage(hWnd, WM_KEYUP, (IntPtr)VirtualKeyStates.VK_SHIFT, (IntPtr)0); } else { //send key down SendMessage(hWnd, WM_KEYDOWN, (IntPtr)key, (IntPtr)0); //sleep 50ms Thread.Sleep(50); //send key up SendMessage(hWnd, WM_KEYUP, (IntPtr)key, (IntPtr)0); } }
/// <summary> /// Sends a Keydup message(0x101) to the specified window with a Virtual Key /// </summary> /// <param name="winTitle">Window Title</param> /// <param name="Key">Virtual Key to Send</param> public static void KeyUp(string winTitle, VirtualKeyStates Key) { IntPtr hWnd = FindWindow(null, winTitle); SendMessage(hWnd, 0x101, (IntPtr)Key, (IntPtr)0); }
public static void KeyDown(string winTitle, VirtualKeyStates key) { IntPtr hWnd = FindWindow(null, winTitle); SendMessage(hWnd, WM_KEYDOWN, (IntPtr)key, (IntPtr)0); }
public static void KeyDownAndUp(IntPtr hWnd, VirtualKeyStates key) { KeyDown(hWnd, key); Thread.Sleep(50); KeyUp(hWnd, key); }
public static void KeyUp(IntPtr hWnd, VirtualKeyStates key) { SendMessage(hWnd, WM_KEYDOWN, (IntPtr)key, (IntPtr)0); }
public static bool IsPressed(VirtualKeyStates key) { return Convert.ToBoolean(GetKeyState(key) & 0x8000); }
private static extern short GetKeyState(VirtualKeyStates nVirtKey);
public static bool IsKeyPressed(VirtualKeyStates nVirtKey) { return Convert.ToBoolean(GetKeyState(nVirtKey) & KEY_PRESSED); }
public static extern short GetAsyncKeyState(VirtualKeyStates vKey);
public static extern short GetAsyncKeyState(VirtualKeyStates vKey); // for applications that are not driving the message pump
public static extern short GetKeyState(VirtualKeyStates nVirtKey);
public static bool IsKeyPressed(VirtualKeyStates key) => GetKeyState(key) switch { 0 => false, // Not pressed and not toggled on. 1 => false, // Not pressed, but toggled on
public bool IsPressed(VirtualKeyStates key) { var isPressed = KeyState.IsPressed(key); return isPressed; }
internal static extern short GetKeyState(VirtualKeyStates nVirtKey);
public bool IsPressed(VirtualKeyStates key) { var isPressed = KeyState.IsPressed(key); return(isPressed); }
public static bool IsPressed(VirtualKeyStates key) { return(Convert.ToBoolean(GetKeyState(key) & 0x8000)); }
//KeyHook gkh = new KeyHook(); [DllImport("USER32.dll")] static extern short GetKeyState(VirtualKeyStates nVirtKey);
private bool IsPressed(VirtualKeyStates key) { return Convert.ToBoolean(GetKeyState(key) & KeyPressed); }
public bool IsPressed(VirtualKeyStates key) { return KeyState.IsPressed(key); }
public static extern short GetKeyState(VirtualKeyStates keyCode);
public static bool IsKeyPressed(VirtualKeyStates nVirtKey) { return(Convert.ToBoolean(GetKeyState(nVirtKey) & KEY_PRESSED)); }
public static bool IsKeyPressed(VirtualKeyStates key) { return(Convert.ToBoolean(NativeMethods.GetKeyState(VirtualKeyStates.VK_LBUTTON) & KEY_PRESSED)); }
protected bool IsPressed(VirtualKeyStates key) { return KeyState.IsPressed(key); }
[DllImport("user32")] static extern short GetKeyState(VirtualKeyStates nVirtKey);