blah blah blah is here! blah blah » Close

up0down
link

Hello!
I need to simulate keystrokes. I write the following:

SendKeys.Send("something");
SendKeys.Send("{ENTER}");
SendKeys.Send("%{F4}");
etc.
But I wonder how to send the key which stands between the right Alt and Ctrl, also known as Menu or Application key / http://support.dell.com/support/edocs/acc/sil_6000/app.GIF /. Does anybody know?
Thank you in advance! :)

last answered one year ago

1 answers

up0down
link

SendKeys.Send only seems to be able to deal with 'standard' keys.

To send the application key, I'd try the Win32 function keybd_event instead.

To use this, you need to know the 'virtual key code' (there's a list here). I don't have this key on my keyboard but I'd guess that it's either VK_APPS or VK_RMENU:

// add these declarations
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);

const byte VK_APPS = 0x5D;
const byte VK_RMENU = 0xA5;
const uint KEYEVENTF_KEYUP = 0x02;

// send VK_APPS key with
keybd_event(VK_APPS, 0x45, 0, 0); // generate key down
keybd_event(VK_APPS, 0x45, KEYEVENTF_KEYUP, 0); // generate key up


EDIT

One other thought. Could there be a Windows keyboard shortcut combination which does the same thing as this key and which you could send using SendKeys? How about Shift+F10, for instance, which would be SendKeys.Send("+{F10}")?

Hello! Well I tried SendKeys.Send("+{F10}"), but it caused some runtime errors. But please can you tell me more about the upper method.

vulpes
17279

keybd_event is an unmanaged function included in the Win32 API which can synthesize keystrokes, given their virtual key codes. You have to programatically press the key and then release it. The use of the DllImport attribute allows us to call this function from C#. You'll also need to add: using System.Runtime.InteropServices; to your 'using' directives in order to use this attribute. If the code doesn't work, then it's probably because the virtual key code is not what we're expecting it to be. I googled it but couldn't find anything though Dell's technical support may know.

Feedback