Reputation:
i'm using PostMessage to send windows message(s) to an application. Now, this code works fine when sending any key except ARROW keys (VK_RIGHT or VK_LEFT).
procedure SendKey(key: Variant);
var
lParam: integer;
scancode: integer;
begin
if (VarType(key) = varUString) then
begin
scancode := MapVirtualKey(Ord(VarToStr(key)[1]), MAPVK_VK_TO_VSC);
lParam := scancode shl 16;
PostMessage(_hWindow, WM_KEYDOWN, scancode, lParam);
PostMessage(_hWindow, WM_KEYUP, scancode, lParam);
end else
begin
lParam := MapVirtualKey(key, MAPVK_VK_TO_VSC) shl 16;
PostMessage(_hWindow, WM_KEYDOWN, key, lParam);
PostMessage(_hWindow, WM_KEYUP, key, lParam);
end;
end;
I installed a keyboard hook to monitor the WM_KEYDOWN/UP messages for VK_LEFT/RIGHT to see how the lParam looks like, and i encountered some weird values, here's the DebugView output when pressing RIGHT Arrow Key (VK_RIGHT).
[2776] wParam: 39, lParam: 21823489
[2776] wParam: 39, lParam: -1051918335
if i try to send the messages with these values hardcoded, nothing happens too, any idea what's going on ? thanks.
Upvotes: 0
Views: 1080
Reputation: 612884
It depends on how the application handles input. Sometimes the application handles this directly from the message loop rather than the window procedure. Sometimes applications use raw input instead. Presumably your target application is of this nature.
Generally these questions get asked by people trying to fake input to programs that don't want to accept fake input. It's plausible that you won't be able to fake input to your program. Or you might be able to use SendInput
. It all depends on the target application
If your target application is prepared to accept automation you should use the accepted method for that, UI Automation.
Upvotes: 1