I've been trying to send keystrokes to a notepad window in Delphi. That's the code I have so far:
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
windows,
messages;
var
H : HWND;
begin
H := FindWindowA(NIL, 'Untitled - Notepad');
if H <> 0 then begin
SendMessage(H, WM_KEYDOWN, VK_CONTROL, 1);
SendMessage(H, WM_KEYDOWN, MapVirtualKey(ord('v'), 0), 1);
SendMessage(H, WM_KEYUP, MapVirtualKey(ord('v'), 0), 1);
SendMessage(H, WM_KEYUP, VK_CONTROL, 1);
end;
end.
I've also found this example:
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
windows,
messages;
var
H : HWND;
I : Integer;
s : String;
begin
h := FindWindowA(NIL, 'Untitled - Notepad');
if h <> 0 then
begin
h := FindWindowEx(h, 0, 'Edit', nil);
s := 'Hello';
for i := 1 to Length(s) do
SendMessage(h, WM_CHAR, Word(s[i]), 0);
PostMessage(h, WM_KEYDOWN, VK_RETURN, 0);
PostMessage(h, WM_KEYDOWN, VK_SPACE, 0);
end;
end.
How can I simulate/Send CTRL+V to a Parentwindow so it would also work with other applications? Not every application has the same ClassNames and controls as notepad.