---- In an internal menu, the components can set sensitive keys. If you usually use Alt F in the menu
Enter the submenu of the "File". In addition, we set shortcuts in shortcuts on the desktop, no matter what you
When you press the shortcut you set, you will start the appropriate application. In a plurality of running applications
How to quickly return to the application you need with a button action? This needs to utilize sensitive keys
(HotKey) technology is implemented. This article uses Delphi3.0 development tools to explain the technology in the application.
Method.
First, the sensitive key setting
---- There is a function in WindowsAPI to set sensitive keys, which is as follows:
BoolregisterhotKey
HWNDHWND, the window handle of the sensitive key
INTID, the only sign of this sensitive key
UINTFSMODIFIERS, the auxiliary button of this sensitive key
UINTVK key value for this sensitive key
);
---- The unique indicator of the sensitive key is specified in Window's value range of 0x0000 to 0xBFFF.
There is a value range between 0xC000 to 0xFFF between the dynamic link library. In order to ensure its uniqueness suggestion
The GlobalAddatom function is set to set the unique marker of the sensitive key. Need to pay attention to the value of GlobalAddatom
It is between the 0xc000 to 0xFFFFffffffffffffffffffffffffffffffffffff, and if it is in the application
Setting the sensitive key in the middle can be subtracted from 0xC000 using GlobalAddatom.
---- Auxiliary button of the sensitive key includes mod_ctrl, mod_alt, mod_shift, for Windows Compatible Keyboard
Support for the Windows key, that is, the key with the Windows flag on the key surface, its value is mod_win.
---- Create a "newApplication" in Delphi, add the following in the private segment in TFORM1
Code
Private
{Privateeclarations}
HotKeyID: Integer;
ProcedureWMhotKeyHandle (Varmsg: TMESSAGE);
MessageWM_hotKey; Response Sensitive Key Button Message
Add the following code in the FormCreate event
...
HotKeyId: = GlobalAddatom (Pchar
("UserDefinehotKey)) - $ C000;
Slimming $ C000 is to ensure the limit of the value range
RegisterhotKey (Handle, HotKeyID,
MOD_CONTROLORMOD_ALTT, $ 41);
Sensitive key for Ctrl Alt a
...
Second, the response of sensitive keys
---- Once the sensitive key is set, if there is a corresponding sensitive key during the program application, the Windows system will give
Your app sends a message WM_HOTKEY, whether your application is current activity. Where WM_HOTKEY
The format of the message is:
IDHOTKEY = (int) WPARAM;
This parameter is useful in setting the system-level sensitive key, generally not used
Fumodifiers = (uint) Loword (LPARAM);
Sensitive button auxiliary button
Uvirtkey = (uint) HiWord (LPARAM);
Key value of sensitive keys
---- Because the Windows system is just sent to the application with a message of WM_HOTKEY, you need to complete the specific thing.
A message handler, that is, the private segment
ProcedureWMhotkeyHandle (Varmsg: tMessage); MessageWM_hotKey; process, its code
As shown below (here just simply display the front display of the window)
Proceduretform1.wmhotkeyhandle (Varmsg: tMessage);
Begin
IF (msg.lparamhi = $ 41)
(msg.lparamlo = mod_controlormod_alt) THEN
Begin
msg.result: = 1; this message has been processed
Application.bringtofront;
Put the window in front of the window
END;
END;
Third, the release of sensitive keys
---- Before the application returns out, you should release the sensitive key you set to release the system resources you have, here
Need to call two WindowsAPI functions unregisterhotKey, and its call format is as follows:
BoolunregisterhotKey
HWNDHWND, window handle associated with sensitive keys
INTID sensitive key sign
);
That is to say, just add the following code in the FormClose event.
...
UnregisterhotKey (Handle, HotKeyID);
DELETEATOM (HotKeyID);
...
---- Here, you should have a comprehensive understanding of the sensitive key technology, and the above example is quite simple to provide
To successfully detect it, you can improve according to the specific situation, I hope to help your development process.