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.