Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Send keys to another application

Posted on 2006-10-31
3
Medium Priority
?
4,459 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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 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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

609 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