December 24th, 2025
intriguing1 reaction

Why does my Ctrl+M accelerator key activate when I press the Enter key?

A customer didn’t understand why their Win32 accelerator key for Ctrl+M was triggering spuriously. Specifically, it was triggering when the user hit the Enter key, which is nothing like the Ctrl+M two-key combination.

They defined their accelerator table like this:

IDA_MAIN ACCELERATORS
BEGIN
"^M", IDM_MUMBLE
END

Accelerator key definitions can be done by character or by virtual key code. If you use a quoted string, then you are defining a character accelerator which triggers when that character is entered by whatever means. For example, if you define a character accelerator for "0", it will trigger if the user presses the 0 key on the top row of the keyboard, or if they press the Numpad0 key on the numeric keypad, or even if they type Alt+Numpad4,Numpad8 to type the character by entering its character code on the numeric keypad.

In the above case, the accelerator was defined as the character ^M, which is shorthand for Ctrl+M, or character code 13. There are multiple ways to enter that character code. You could type Ctrl+M on the keyboard, or you could press the Enter key.

If you want the accelerator to trigger only for the case of Ctrl+M, then you want to define a virtual key accelerator, not a character accelerator.

IDA_MAIN ACCELERATORS
BEGIN
"M", IDM_MUMBLE, CONTROL, VIRTKEY
END

Virtual key accelerators trigger only when the specified keys are pressed. In our case, we want the M virtual key in combination with the CTRL key.

Conversely, if you want the accelerator to trigger only for the Enter key, you would specify that key as a virtual key.

IDA_MAIN ACCELERATORS
BEGIN
VK_RETURN, IDM_MUMBLE, VIRTKEY
END

There are two more key-to-control-character combinations that you may stumble across.

  • Backspace becomes the character ^H.
  • Tab becomes the character ^I.

Technically, there is a third combination:

  • Esc becomes the character ^[.

However, the Resource Compiler does not accept "^[" as a control key, so you aren’t going to run into that one by mistake.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments