Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've found this example on internet. Tested it on my own when I tried to do the same thing as you are trying now.</p> <pre><code>[Flags] private enum InputType { Mouse = 0, Keyboard = 1, Hardware = 2 } [Flags] private enum KeyEventF { KeyDown = 0x0000, ExtendedKey = 0x0001, KeyUp = 0x0002, Unicode = 0x0004, Scancode = 0x0008, } [DllImport("user32.dll", SetLastError = true)] private static extern uint SendInput(uint nInputs, Input[] pInputs, int cbSize); [DllImport("user32.dll")] private static extern IntPtr GetMessageExtraInfo(); public static void SendKey(ushort key) { Input[] inputs = { new Input { type = (int) InputType.Keyboard, u = new InputUnion { ki = new KeyboardInput { wVk = 0, wScan = key, dwFlags = (uint) (KeyEventF.KeyDown | KeyEventF.Scancode), dwExtraInfo = GetMessageExtraInfo() } } } }; SendInput((uint) inputs.Length, inputs, Marshal.SizeOf(typeof (Input))); } private struct Input { public int type; public InputUnion u; } [StructLayout(LayoutKind.Explicit)] private struct InputUnion { [FieldOffset(0)] public readonly MouseInput mi; [FieldOffset(0)] public KeyboardInput ki; [FieldOffset(0)] public readonly HardwareInput hi; } [StructLayout(LayoutKind.Sequential)] private struct MouseInput { public readonly int dx; public readonly int dy; public readonly uint mouseData; public readonly uint dwFlags; public readonly uint time; public readonly IntPtr dwExtraInfo; } [StructLayout(LayoutKind.Sequential)] private struct KeyboardInput { public ushort wVk; public ushort wScan; public uint dwFlags; public readonly uint time; public IntPtr dwExtraInfo; } [StructLayout(LayoutKind.Sequential)] private struct HardwareInput { public readonly uint uMsg; public readonly ushort wParamL; public readonly ushort wParamH; } </code></pre> <p>Now use <code>SendKey(0x14)</code> to send your <code>T</code> key to the active window (or game).</p> <p><strong>Note: You need <code>KeyEventF.Scancode</code> as your flag or the <code>wScan</code> property will be ignored!</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload