public void ReleaseKey(Keys keyCode) { var structInput = new INPUT(); structInput.type = 1; structInput.ki.wScan = 0; structInput.ki.time = 0; structInput.ki.dwFlags = 0; structInput.ki.dwExtraInfo = 0; // Key up the actual key-code structInput.ki.dwFlags = NativeWin32.KEYEVENTF_KEYUP; structInput.ki.wVk = (ushort)keyCode;// (ushort)NativeWin32.VK.SNAPSHOT;//vk; NativeWin32.SendInput(1, ref structInput, Marshal.SizeOf(structInput)); }
public static extern uint SendInput(uint nInputs, ref INPUT pInputs, int cbSize);
public void PressKey(Keys keyCode) { var structInput = new INPUT(); structInput.type = 1; structInput.ki.wScan = 0; structInput.ki.time = 0; structInput.ki.dwFlags = 0; structInput.ki.dwExtraInfo = 0; // Key down the actual key-code structInput.ki.wVk = (ushort)keyCode; //VK.SHIFT etc. NativeWin32.SendInput(1, ref structInput, Marshal.SizeOf(structInput)); }