I am pretty sure the following button-activated form code should raise a Control-F12 in my C# application:
SendKeys(‘^{F12}’);
But it does not appear to go on up to the windows shell and activate another program that is listening for it. My keyboard does work. It seems like the sendkeys is getting intercepted somewhere and not sent on in a way that actually simulates the key stroke. Any help?
SendKeys is not capable of sending keys outside of the active application.
To really and truly simulate a keystroke systemwide, you need to P/Invoke either
keybd_eventorSendInputout ofuser32.dll. (According to MSDNSendInputis the ‘correct’ way butkeybd_eventworks and is simpler to P/Invoke.)Example (I think these key codes are right… the first in each pair is the
VK_code, and the second is the make or break keyboard scan code… the ‘2’ isKEYEVENTF_KEYUP)The alternative is to activate the application you’re sending to before using SendKeys. To do this, you’d need to again use P/Invoke to find the application’s window and focus it.