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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get any key in other windows apps 2

Status
Not open for further replies.

Gigatech

Programmer
Jul 12, 2000
80
CR
Hi,
I´m using Delphi 7. I want to get any key pressed in another application and handle it in my delphi program. For example, if the user is using Excel and press "*" I want to display a list of names stored in a table.

Thanks
 
I came accross this post in Experts Exchange by BTecho while searching for application wide hotkeys, this is for CTRL + b for anything else change the MOD_CONTROL, and ord('c') to whatever you want:

//In the main form's OnCreate event
//assign the hotkey handler
If not RegisterHotkey
(Handle, 1, MOD_CONTROL , ord('C')) Then
ShowMessage('Unable to assign Ctrl+C as hotkey.');

//In the main forms OnClose event
//remove the hotkey handler:
UnRegisterHotkey( Handle, 1 );


//Add a handler for the
//WM_HOTKEY message to the form:

private // form declaration
Procedure WMHotkey( Var msg: TWMHotkey );
message WM_HOTKEY;

Procedure TForm1.WMHotkey( Var msg: TWMHotkey );
Begin
If msg.hotkey = 1 Then Begin
//now simulate alt+tab
keybd_event(Key, VK_MENU, 0, 0);
keybd_event(Key, VK_TAB, 0, 0);
keybd_event(Key, VK_TAB, KEYEVENTF_KEYUP, 0);
keybd_event(Key, VK_MENU, KEYEVENTF_KEYUP, 0);
End;
 
Replace
----
//now simulate alt+tab
keybd_event(Key, VK_MENU, 0, 0);
keybd_event(Key, VK_TAB, 0, 0);
keybd_event(Key, VK_TAB, KEYEVENTF_KEYUP, 0);
keybd_event(Key, VK_MENU, KEYEVENTF_KEYUP, 0);
----
with the action you will take.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top