My question is how to send shortcut from c++ to another application. Let's say for example that the notepad is open, and I want send to them shortcut like CTRL+P, or more complexive shortcut like CTRL+SHIFT+HOME, or ALT+F4, I find many good tutorials that explained how to send one key like 'A' or 'ALT', but I did not find how to send it together.
A:
You can send a number of WM_KEYDOWNs followed by a number of WM_KEYUPs so you could try sending DOWN ctrl, shift, home, UP home, shift, ctrl - that should do the trick.
Will A
2010-08-15 17:09:49
+1
A:
You can use SendInput()
or keybd_event()
to send keys to the currently focused window. SendInput()
might be the better choice as it would not intersperse the keyboard events with those form the actual keyboard.
// send CTRL+SHIFT+HOME
INPUT input[6];
memset(input, 0, sizeof(INPUT)*6);
input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = VK_CONTROL;
input[1].type = INPUT_KEYBOARD;
input[1].ki.wVk = VK_SHIFT;
input[2].type = INPUT_KEYBOARD;
input[2].ki.wVk = VK_HOME;
input[3].type = INPUT_KEYBOARD;
input[3].ki.wVk = VK_HOME;
input[3].ki.dwFlags = KEYEVENTF_KEYUP;
input[4].type = INPUT_KEYBOARD;
input[4].ki.wVk = VK_SHIFT;
input[4].ki.dwFlags = KEYEVENTF_KEYUP;
input[5].type = INPUT_KEYBOARD;
input[5].ki.wVk = VK_CONTROL;
input[5].ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(6, input, sizeof(INPUT));
gwell
2010-08-15 18:14:04
A:
This kind of "key combinations" is usually called Keyborad Accelerators in Microsoft Windows. The MSDN intro page
MSalters
2010-08-16 11:53:46