tags:

views:

1072

answers:

3

I am writing a C# program which captures signals from a external device, and sends keystrokes to another application. I am using SendKeys and it works fine.

SendKeys does "press" a key by holding and releasing it immediately. I would like to make it push key and release it at will.

My question is : "is there a way to send a "push" signal to a key, then a "release" signal after a certain amount of time ?"

I am not sure SendKeys is able to do this. Any clue ?

+4  A: 

I don't think it's possible from .NET directly You could try using keybd_event native call by p/invoking the funtion as described here: http://pinvoke.net/default.aspx/user32.keybd_event

The MSDN for keybd_event is here: http://msdn.microsoft.com/en-us/library/ms646304(VS.85).aspx

Hope that helps!

Adam Haile
Nice ! Worked fine to me. Thank you very much !
controlbreak
+3  A: 

You could use SendInput or keyb_event, both are native API functions. SendInput has some advantages over keybd_event, but SendInput is only available starting with XP.

Here is the msdn link http://msdn.microsoft.com/en-us/library/ms646310.aspx

Hope this helps

Dan Cristoloveanu
+1  A: 

I once was looking to do the same thing on powerpoint, to hide the cursor, and later to stop the slideshow. But it's hard and tricky as there's many top level windows appeared in powerpoint, also it's hard to figure out which part of the emulation failed if it doesn't work. After looking into the message queue using Spy++, I notice that the accelerator command was sent after the keypress, so instead, I emulated the accelerator command, and it works like charm. So you might want to look into alternative like this.

faulty