I have a task where I need to put some mouse clicks on web form displayed in browser, and also do some keyboard input, as fill the text box with numbers or make sequence of pressing down arrows in order to get choice in combo box.
Window handlers I have, coordinates where click too, it works fine for me (very simple function):
extern "C" __declspec(dllexport) void __stdcall PutSingleClick(unsigned hwnd, int x, int y) { SendMessage(((HWND) hwnd), WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(x, y)); SendMessage(((HWND) hwnd), WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(x, y)); } My problem appears while I try to send keyboard input, as for example by calling:
extern "C" __declspec(dllexport) void __stdcall PutKeystrokeDown(int times) { INPUT ip; ip.type = INPUT_KEYBOARD; ip.ki.time = 0; ip.ki.wVk = 0; ip.ki.dwExtraInfo = 0; ip.ki.wScan = VK_DOWN; for(int i = 0; i < times; i++) { ip.ki.dwFlags = KEYEVENTF_SCANCODE; SendInput(1, &ip, sizeof(INPUT)); ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP; SendInput(1, &ip, sizeof(INPUT)); } ip.ki.dwFlags = KEYEVENTF_SCANCODE; ip.ki.wScan = VK_RETURN; SendInput(1, &ip, sizeof(INPUT)); ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP; SendInput(1, &ip, sizeof(INPUT)); } After calling this function nothing done, only in input buffer remains strange character (" ´ " [akcent, dead character] in my case).
While I try to catch what happens by Spy++, mouse events (clicks) are spied correctly (when generated both manually and by program), but keyboard ones not - either program or manual.
While I try utility On screen keyboard (common part of Windows), it works as good as hardware keyboard (numbers was inputed, chosen value are changed....), but no messages is generated.
Any idea how emulate hardware keystrokes and put sequence where I need?
Thanks a lot.