/// <summary> /// Emulates the key press event using the virtual key codes /// </summary> void SendKey(ushort code) { Win32Services.INPUT structInput; structInput = new Win32Services.INPUT(); structInput.type = (uint)1; structInput.ki.wScan = 0; structInput.ki.time = 0; structInput.ki.dwFlags = 0; structInput.ki.dwExtraInfo = 0; if (code < 256) { // set to the virtual key code structInput.ki.wVk = code; Input(ref structInput); structInput.ki.dwFlags = Win32Services.KEYEVENTF_KEYUP; Input(ref structInput); } else // shift { code -= 256; structInput.ki.wVk = 16; // SHIFT CODE Input(ref structInput); structInput.ki.wVk = code; Input(ref structInput); structInput.ki.dwFlags = Win32Services.KEYEVENTF_KEYUP; Input(ref structInput); structInput.ki.wVk = 16; Input(ref structInput); } }
void Input(ref Win32Services.INPUT sI) { Win32Services.SendInput(1, ref sI, Marshal.SizeOf(sI)); }