Share via


Creating Keyboard Accelerators (Windows Embedded CE 6.0)

1/6/2010

A keyboard accelerator, also known as a shortcut key, is a keystroke or combination of keystrokes that generates a WM_COMMAND message. Keyboard accelerators are often used as shortcuts for commonly used menu commands, but you can also use them to generate commands that have no equivalent menu items. Include keyboard accelerators for any common or frequent actions, and provide support for the common shortcut keys where they apply.

You can use an ASCII character code or a virtual key code to define the accelerator. A virtual key is a device-independent value that identifies the purpose of a keystroke as interpreted by the Windows keyboard device driver. An ASCII character code makes the accelerator case sensitive. The ASCII C character can define the accelerator as ALT+c rather than ALT+C. Because accelerators do not need to be case-sensitive, most applications use virtual key codes for accelerators rather than ASCII character codes.

If an application defines an accelerator that is also defined in the system accelerator table, the application–defined accelerator overrides the system accelerator, but only within the application context. Avoid this, because it prevents the system accelerator from performing its standard role in the Windows Embedded CE user interface (UI).

To create an accelerator table

  1. Use a resource compiler to define an accelerator table resource and add it to your executable file.

    An accelerator table consists of an array of ACCEL data structures, each of which defines an individual accelerator.

  2. Call the LoadAccelerators function at run time to load the accelerator table and to retrieve the handle of the accelerator table.

  3. Pass a handle to the accelerator table to the TranslateAccelerator function to activate the accelerator table.

You can also create an accelerator table for an application at run time by passing an array of ACCEL structures to the CreateAcceleratorTable function. This method supports user-defined accelerators in the application. CreateAcceleratorTable creates an accelerator table that must be destroyed before an application closes. Call the DestroyAcceleratorTable function to destroy the accelerator table.

See Also

Concepts

Using Resources

Other Resources

Keyboard
GWES Application Development