Solved

Send keys to another application

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

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

820 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