public void WriteText(string characters) { var inputs = new NativeMethods.INPUT[2 * characters.Length]; for (int i = 0; i < inputs.Length; i++) { var ki = new NativeMethods.KEYBDINPUT { dwFlags = NativeMethods.KEYEVENTF.UNICODE }; if (i % 2 == 1) { ki.dwFlags |= NativeMethods.KEYEVENTF.KEYUP; } ki.wScan = (short)characters[i / 2]; var input = new NativeMethods.INPUT(); input.type = NativeMethods.INPUT_KEYBOARD; input.U.ki = ki; inputs[i] = input; } if (NativeMethods.SendInput((uint)inputs.Length, inputs, NativeMethods.INPUT.Size) == 0) { throw new Win32Exception(); } }
private void PressOrReleaseKey(VirtualKeyShort keyCode, bool down) { var ki = new NativeMethods.KEYBDINPUT { wVk = keyCode }; if (!down) { ki.dwFlags = NativeMethods.KEYEVENTF.KEYUP; } var input = new NativeMethods.INPUT(); input.type = NativeMethods.INPUT_KEYBOARD; input.U.ki = ki; NativeMethods.INPUT[] inputs = { input }; if (NativeMethods.SendInput((uint)inputs.Length, inputs, NativeMethods.INPUT.Size) == 0) { throw new Win32Exception(); } }
public void WriteText(string characters) { NativeMethods.INPUT[] inputs = new NativeMethods.INPUT[2 * characters.Length]; for (int i = 0; i < inputs.Length; i++) { var ki = new NativeMethods.KEYBDINPUT(); ki.dwFlags = NativeMethods.KEYEVENTF.UNICODE; if (i % 2 == 1) ki.dwFlags |= NativeMethods.KEYEVENTF.KEYUP; ki.wScan = (short)characters[i / 2]; var input = new NativeMethods.INPUT(); input.type = NativeMethods.INPUT_KEYBOARD; input.U.ki = ki; inputs[i] = input; } if (NativeMethods.SendInput((uint)inputs.Length, inputs, NativeMethods.INPUT.Size) == 0) throw new System.ComponentModel.Win32Exception(); }
private void PressOrReleaseKey(VirtualKeyShort keyCode, bool down) { var ki = new NativeMethods.KEYBDINPUT(); ki.wVk = keyCode; if (!down) ki.dwFlags = NativeMethods.KEYEVENTF.KEYUP; var input = new NativeMethods.INPUT(); input.type = NativeMethods.INPUT_KEYBOARD; input.U.ki = ki; NativeMethods.INPUT[] inputs = { input }; if (NativeMethods.SendInput((uint)inputs.Length, inputs, NativeMethods.INPUT.Size) == 0) throw new System.ComponentModel.Win32Exception(); }