SAMPLE: Creating a Shortcut-Key Edit Control

Last reviewed: February 15, 1996
Article ID: Q83914
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows version 3.1

SUMMARY

HOTKEYED is a file in the Microsoft Software Library that demonstrates how to implement a shortcut-key edit control. A user can define a shortcut key for an application. When the user presses the shortcut key, Windows activates the corresponding application.

Download HOTKEYED.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download HOTKEYED.EXE (size: 25821 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get HOTKEYED.EXE (size: 25821 bytes) 
    

MORE INFORMATION

HOTKEYED 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 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 reference words: 3.10 softlib HOTKEYED.EXE
KBCategory: kbprg kbfile
KBSubcategory: UsrCtl


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 15, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.