Solved

Send keys to another application

Posted on 2006-10-31
3
4,185 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
  • 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 100 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

772 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