0

Here is my code:

keybd_event(VK_MENU, 0, 0, 0);
keybd_event(VK_RETURN, 0, 0, 0);
Sleep(200);
keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);

The first line would press Alt
The second line would press Enter ↵ (or Return ↵),
The fourth line would release Alt,
The fifth line would release Enter ↵ (or Return ↵).

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79

1 Answers1

1

You are not setting the KEYEVENTF_EXTENDEDKEY flag to keep the keys pressed down. Change your code to:

keybd_event(VK_MENU, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_RETURN, 0, KEYEVENTF_EXTENDEDKEY, 0);
Sleep(200);
keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);

Also you really don't need the sleep in the middle if you are just sending a Alt + Enter

You can see all of the keycodes here at the MSDN page.

  • Alt = VK_MENU
  • Left Alt = VK_LMENU
  • Right Alt Gr = VK_RMENU
Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
NathanOliver
  • 171,901
  • 28
  • 288
  • 402