KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am using this board as a keyboard for demo purposes. Anyways to make the long story short everything works fine except for very few cases. I send keystrokes with the SendInput function located in user32.dll. So my program looks like: static void Main(string[] args) { Console.Write("Press enter an on the next secont the key combination shift+end will be send"); Console.Read(); Thread.Sleep(1000); SendKeyDown(KeyCode.SHIFT); SendKeyPress(KeyCode.END); SendKeyUp(KeyCode.SHIFT); Console.Read(); Console.Read(); } [DllImport("user32.dll", SetLastError = true)] private static extern uint SendInput(uint numberOfInputs, INPUT[] inputs, int sizeOfInputStructure); /// <summary> /// simulate key press /// </summary> /// <param name="keyCode"></param> public static void SendKeyPress(KeyCode keyCode) { INPUT input = new INPUT { Type = 1 }; input.Data.Keyboard = new KEYBDINPUT() { Vk = (ushort)keyCode, Scan = 0, Flags = 0, Time = 0, ExtraInfo = IntPtr.Zero, }; INPUT input2 = new INPUT { Type = 1 }; input2.Data.Keyboard = new KEYBDINPUT() { Vk = (ushort)keyCode, Scan = 0, Flags = 2, Time = 0, ExtraInfo = IntPtr.Zero }; INPUT[] inputs = new INPUT[] { input, input2 }; if (SendInput(2, inputs, Marshal.SizeOf(typeof(INPUT))) == 0) throw new Exception(); } /// <summary> /// Send a key down and hold it down until sendkeyup method is called /// </summary> /// <param name="keyCode"></param> public static void SendKeyDown(KeyCode keyCode) { INPUT
Tags (comma-separated)
Save Edits
Cancel