I've been trying to resolve this for weeks now. I'm trying to create an app in Delphi that runs in the background and catches any hot key and executes Ctrl + c. So what I did is I catch the hot key for example ALT + right arrow then simulate Ctrl + c and throw the command to the current window.
What I noticed is that when I try sending commands to Firefox like below:
SendMessage(FireFoxHandle, WM_COPY, 0, 0);
sleep(250);
CopiedText := ClipBoard.AsText;
Copying was successful and I get the expected text. But once I used the same line of codes to other windows like chrome(chrome_widget_1) or notepad, I can't get anything. So what I tried is get the child window of the chrome and notepad and try to send the command to the child window.
Got "Chrome Legacy Window" as child of "chrome_widget_1" window but when i try to select a text in the tab, simulate the Ctrl + c, still not working.
Found an example here in stackoverflow for sending wm_copy to notepad's child window which is an edit like the code below:
ParentWindw := FindWindow('Notepad',nil);
if ParentWindow <> 0 then
begin
ChildWindow := FindWindowEx(ParentWindow, 0, 'Edit', nil);
SendMessage(ChildWindow, WM_COPY, 0, 0);
sleep(250);
CopiedText := ClipBoard.AsText;
end;
The code works but is there any dynamic way to determine the child window that i need to use for the wm_copy command? I'm asking not only for the notepad window but for all possible window that can be used.
Or is there anyway where I can copy the highlighted text in any window Programmatically in Delphi specifically in xe2?
I already researched already like sendinput, keyevents and tried them but no luck. I'm running out of option how to make it work.
Thanks for any help in advance.