Solved

Send keys to another application

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

709 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now