private void InternalSetKeyUp(int virtualKeyCode) { var keys = new byte[256]; Win32Imports.GetKeyboardState(keys); keys[virtualKeyCode] &= 0x00; Win32Imports.SetKeyboardState(keys); var foreignThreadId = Win32Imports.GetWindowThreadProcessId(_processWindowHandle, IntPtr.Zero); var localThreadId = Win32Imports.GetCurrentThreadId(); Win32Imports.AttachThreadInput(localThreadId, foreignThreadId, false); Thread.Sleep(50); }
private void InternalSetKeyDown(int virtualKeyCode) { var foreignThreadId = Win32Imports.GetWindowThreadProcessId(_processWindowHandle, IntPtr.Zero); var localThreadId = Win32Imports.GetCurrentThreadId(); Win32Imports.AttachThreadInput(localThreadId, foreignThreadId, true); var keys = new byte[256]; Win32Imports.GetKeyboardState(keys); keys[virtualKeyCode] |= 0x80; Win32Imports.SetKeyboardState(keys); Task.Delay(50).Wait(); }