Click here to Skip to main content
15,888,000 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I posted the full question on StackOverFlow:
http://stackoverflow.com/questions/3554171/cant-send-a-single-key-function-to-remote-desktop


Long story short:
Im able to send text to the remote computer but not single key strokes (meaning as keys, not as a string).

I think the solution is that i need to use the MapVirtualKey method, just dont know how to use is correctly...

In this example the scan code is 0, i assume it suppose to be the return value of MapVirtualKey...

If you could please help me with this example and ill be on my way:

public static void SimulateKeyDown(VirtualKeyCode keyCode)
 {
     var down = new INPUT();
     down.Type = (UInt32)InputType.KEYBOARD;
     down.Data.Keyboard = new KEYBDINPUT();
     down.Data.Keyboard.Vk = (UInt16)keyCode;
     down.Data.Keyboard.Scan =0
     down.Data.Keyboard.Flags = 0;
     down.Data.Keyboard.Time = 0;
     down.Data.Keyboard.ExtraInfo = IntPtr.Zero;

     INPUT[] inputList = new INPUT[1];
     inputList[0] = down;

     var numberOfSuccessfulSimulatedInputs = SendInput(1, inputList, Marshal.SizeOf(typeof(INPUT)));
     if (numberOfSuccessfulSimulatedInputs == 0) throw new Exception(string.Format("The key down simulation for {0} was not successful.", keyCode));
 }




Many Thanks Ahead,
Niv.
Posted
Updated 29-Aug-10 4:22am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900