Hi all,
Trying to send keystrokes to an application on Windows 11 I have this code ...
var
wndMain: HWND;
r:LResult;
scanCode:UINT;
l:LPARAM;
w:WPARAM;
begin
// wndMain := FindWindow(PChar(aClassName),nil);
wndMain := FindWindow('Notepad',nil);
DoShowStatus('Window Handle: ' + IntToStr(wndMain));
if wndMain <> 0 then
begin
l := 0;
// scanCode := MapVirtualKey(VK_A, 0);
// l := ($00000001 OR (scanCode SHL 16));
r := SendMessage(wndMain,WM_KEYDOWN,VK_A,l);
// l := l OR $C0000000;
r := SendMessage(wndMain,WM_KEYUP,VK_A,l);
end;
end;
The objective is to send a specific keystroke (I choose VK_A for testing) to an application, to try I choose notepad.
Finding the hwnd for notepad seems to work, a value is returned.
Unfortunately there is no reaction in Notepad, no keystrokes show up, though SendMessage returns 0. I tried PostMessage too, same behaviour. Regarding the bitmask for lParam, I took it from the AutoIt source code, but using it (commented out) doesn't change anything.
Can anyone provide a working code sample showing how I need to use SendMessage or PostMessage? From what I read I should prefer PostMessage.
Thnx, Armin.