TheLeader
asked on
Selected Text From an Active Window
Greeting...
How can I read selected text from an Active Window [using hot key] without the need to know title name or program name, modify the text in my program, and send it back to the same window I toke it from ?
Selected text from an active window => modify it => replace the selected text with the modify text.
please i need a clear code, i don't know much about API
thank you.
How can I read selected text from an Active Window [using hot key] without the need to know title name or program name, modify the text in my program, and send it back to the same window I toke it from ?
Selected text from an active window => modify it => replace the selected text with the modify text.
please i need a clear code, i don't know much about API
thank you.
Replace the lines above
keybd_event(ORD('c'), 0, 0, 0);
keybd_event(ORD('c'), 0, KEYEVENTF_KEYUP, 0);
with
keybd_event(ORD('C'), 0, 0, 0);
keybd_event(ORD('C'), 0, KEYEVENTF_KEYUP, 0);
Sorry.
keybd_event(ORD('c'), 0, 0, 0);
keybd_event(ORD('c'), 0, KEYEVENTF_KEYUP, 0);
with
keybd_event(ORD('C'), 0, 0, 0);
keybd_event(ORD('C'), 0, KEYEVENTF_KEYUP, 0);
Sorry.
ASKER
geobul, it seems (did not tested yet) your code will work perfect, but it uses clipboard
can you do it in another way, I don't want the user loses clipboard data.
thank you
can you do it in another way, I don't want the user loses clipboard data.
thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect :)
do you suggest any book, website, or article to help as you wrote this code ?
thank you.
do you suggest any book, website, or article to help as you wrote this code ?
thank you.
You are welcome :-)
Except GetWindowText function which I already had I wrote the rest using Delphi help (Win32 Programmer's Reference mainly) and the MSDN site http://msdn.microsoft.com
Regards, Geo
Except GetWindowText function which I already had I wrote the rest using Delphi help (Win32 Programmer's Reference mainly) and the MSDN site http://msdn.microsoft.com
Regards, Geo
uses Clipbrd;
var s: string;
begin
// Ctrl-C
keybd_event(VK_CONTROL, 0, 0, 0);
keybd_event(ORD('c'), 0, 0, 0);
keybd_event(ORD('c'), 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
if Clipboard.HasFormat(CF_TEX
s := Clipboard.AsText; // get the text
if Length(s) > 0 then begin
s:= 'Hello'; // modigy it here. You must write your own code instead of this line
Clipboard.SetTextBuf(PChar
// Ctrl-V
keybd_event(VK_CONTROL, 0, 0, 0);
keybd_event(ORD('V'), 0, 0, 0);
keybd_event(ORD('V'), 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
end;
end;
end;
Regards, Geo