SAMPLE: HotKeyed.exe Creates a Shortcut-Key Edit Control

ID: Q83914

The information in this article applies to:

SUMMARY

HotKeyed.exe is a sample that demonstrates how to implement a shortcut-key edit control so a user can define a shortcut key for your application. When the user presses the shortcut key, Windows activates the corresponding application.

MORE INFORMATION

The following file is available for download from the Microsoft Software Library:

 ~ HotKeyed.exe (size: 25821 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from Online Services

HotKeyed.exe demonstrates how an application can implement a shortcut-key (hot key) edit control. The application contains a dialog box in which the user can specify which shortcut key the application will use. This dialog box uses a subclassed edit control to display the name of the shortcut key entered by the user. The edit control verifies that the shortcut key is valid before displaying its name, and the control does not permit the user to enter an invalid shortcut key. HOTKEYED calls the GetKeyNameText function to retrieve the names of the specified keys.

After the user enters a valid shortcut key, the application will install the shortcut key. Hotkeyed.exe installs a shortcut key by calling the SetWindowsHookEx function to install a task-specific keyboard hook. The application provides a menu selection to remove the shortcut key. Closing the application also removes the shortcut key.

Once the shortcut key is installed, the application's window caption flashes to inform the user that a shortcut key is active. The caption continues to flash until the shortcut key is removed. When the user presses the shortcut key, the background color of the main window changes.

A shortcut key must use the ALT key and/or the CTRL key as a modifier. The SHIFT key can also be specified as a modifier, but only in combination with the ALT and/or CTRL keys. The ESC, ENTER, TAB, and PRINT SCREEN keys and the SPACEBAR are not valid shortcut keys.

The user can erase a key combination from the shortcut key edit control with the BACKSPACE key. Alternatively, the user can enter a different shortcut key.

Additional query words: Keywords : kbfile kbsample kb16bitonly kbInput kbGrpUser kbWinOS310

Last Reviewed: December 13, 1998