Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I send key presses to a component? 1

Status
Not open for further replies.

Wings

Programmer
Feb 14, 2002
247
US
Assuming that a component has an onKeyup() function.
How do I make use of this function to send it different keystrokes in code. For example if i want to send a form the key strokes - H E L L O. How would I do this in code, rather than by typing it on the keyboard during runtime?

Help is appreciated
 
Well (this & similar stuff has just been driving me crazy, too) - first, make sure the component has focus with SetFocus(), then try:

string str="Hello.";
BYTE key;
for(int i=0;i<str.length();i++){
key=(BYTE)str;
keybd_event(key,0,0,0);
}

(Then 'keybd_event(VK_RETURN,0,0,0);' if you wanted to enter it.)
& if anyone reads this & knows how to pass focus to an exe in a shell, PLEASE gimme a shout!

Hope that helps, man.

Douglas JL

If it don't make you laugh, it ain't true.
 
Sorry - line 4 in the code should have read:
key=(BYTE)str;

& I don't know what's going on with the italics.

If it don't make you laugh, it ain't true.
 
Sorry - just realised that the use of i as a variable has made everything italic. So it should read:

string str=&quot;Hello.&quot;;
BYTE key;
for(int n=0;n<str.length();n++){
key=(BYTE)str[n];
keybd_event(key,0,0,0);
}
keybd_event(VK_RETURN,0,0,0); //if you want to hit enter afterwards.

Cheers,
Douglas JL

If it don't make you laugh, it ain't true.
 
You saved me, thanks.
I've been trying to figure that out for a while now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top