?
Solved

Send keys to another application

Posted on 2006-10-31
3
Medium Priority
?
4,374 Views
Last Modified: 2008-01-09
There are several examples of send keys solutions out there. However, I cant seem to get or locate the Virtual Key codes for ")" and other special characters.

Presently, I am away from my development box (on vacation) and wanted to know if what I have written below looks like it will work. if not, I would really appreciate someone to provide me an example of passing these special characters without passing focus or taking focus. Just simply send them to anohter application on a button click
==================================================
procedure TForm1.Button1Click(Sender: TObject);
var hwndNotepad : THandle;
begin
hwndWinamp := FindWindow('NOTEPAD',nil);
SendMessage(hwndNotepad, WM_KEYDOWN, VK_OEM_1, 0);
SendMessage(hwndNotepad, WM_KEYUP, VK_OEM_1, 0);
SendMessage(hwndNotepad, WM_KEYDOWN, VK_OEM_MINUS, 0);
SendMessage(hwndNotepad, WM_KEYUP, VK_OEM_MINUS, 0);
SendMessage(hwndNotepad, WM_KEYDOWN, VK_SHIFT, 0);
SendMessage(hwndNotepad, WM_KEYDOWN, VK_0, 0); //Assuming I need a Shift+0 to get the ")"
SendMessage(hwndNotepad, WM_KEYUP, VK_SHIFT, 0);
SendMessage(hwndNotepad, WM_KEYUP, VK_0, 0);
end;
==================================================
 
In this example, I am assuming that I must do a keydown for shift etc and then the key I want in order to virtually type the desired character(s). Is this correct..?

Q2
.
0
Comment
Question by:quantum2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Expert Comment

by:tobjectpascal
ID: 17840646
keybd_Event(ord('X'), 0, 0, 0);{key down}
keybd_Event(ord('X'), 0, KEYEVENTF_KEYUP, 0);{key up}
keybd_event(VK_F7,0,0,0);
keybd_event(VK_F7,0,KEYEVENTF_KEYUP,0);
0
 
LVL 28

Accepted Solution

by:
TName earned 400 total points
ID: 17840770
As tobjectpascal said, or (you have to address the editor component inside notepad!):

procedure TForm1.Button1Click(Sender: TObject);
var
hnp:HWND;
begin
 hnp:= FindWindow('notepad',nil);
 if hnp>0 then begin
  hnp:=FindWindowEx(hnp,0,'Edit',nil);
  SendMessage(hnp, WM_CHAR, Ord('H'),0);
  SendMessage(hnp, WM_CHAR, Ord('i'),0);
  SendMessage(hnp, WM_CHAR, Ord('!'),0);
  PostMessage(hnp, WM_KEYDOWN, VK_RETURN,0);
 end;
end;
0
 
LVL 28

Expert Comment

by:TName
ID: 17840870
BTW, you don't need the virtual shift key to output a  ")"
This will do:
SendMessage(hnp, WM_CHAR, Ord(')'),0);
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question