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.
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;
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.