How to press the keys on keyboard without using keyboard?
I want my program to press certain keys on my keyboard without me doing it physically.
How i do this?
Edit: found this keybd_event() function. seem to be wor开发者_如何学Pythonking http://www.codeproject.com/KB/cpp/sendkeys_cpp_Article.aspx
There is SendInput function that can generate keystrokes and other kinds of input. I have used to create application similar to virtual keyboards.
Example using Unicode:
// This may be needed
// #define _WIN32_WINNT 0x0501
#include <windows.h>
#include <winuser.h>
void pressKey(WORD a_unicode)
{
KEYBDINPUT kbinput;
ZeroMemory(&kbinput, sizeof(kbinput));
kbinput.wScan = a_unicode;
kbinput.dwFlags = KEYEVENTF_UNICODE;
kbinput.time = 0;
INPUT input;
ZeroMemory(&input, sizeof(input));
input.type = INPUT_KEYBOARD;
input.ki = kbinput;
SendInput(1, &input, sizeof(input));
}
Send Key Events
Use SendMessage with WM_KEYDOWN
Example:
SendMessage(hwnd, WM_KEYDOWN, VK_T, NULL);
精彩评论