{"id":111908,"date":"2025-12-24T07:00:00","date_gmt":"2025-12-24T15:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=111908"},"modified":"2025-12-24T09:58:22","modified_gmt":"2025-12-24T17:58:22","slug":"20251224-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20251224-00\/?p=111908","title":{"rendered":"Why does my <KBD>Ctrl<\/KBD>+<KBD>M<\/KBD> accelerator key activate when I press the <KBD>Enter<\/KBD> key?"},"content":{"rendered":"<p>A customer didn&#8217;t understand why their Win32 accelerator key for <kbd>Ctrl<\/kbd>+<kbd>M<\/kbd> was triggering spuriously. Specifically, it was triggering when the user hit the <kbd>Enter<\/kbd> key, which is nothing like the <kbd>Ctrl<\/kbd>+<kbd>M<\/kbd> two-key combination.<\/p>\n<p>They defined their accelerator table like this:<\/p>\n<pre>IDA_MAIN ACCELERATORS\r\nBEGIN\r\n\"^M\", IDM_MUMBLE\r\nEND\r\n<\/pre>\n<p>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 <tt>\"0\"<\/tt>, it will trigger if the user presses the <kbd>0<\/kbd> key on the top row of the keyboard, or if they press the <kbd>Numpad0<\/kbd> key on the numeric keypad, or even if they type <kbd>Alt<\/kbd>+<kbd>Numpad4<\/kbd>,<kbd>Numpad8<\/kbd> to type the character by entering its character code on the numeric keypad.<\/p>\n<p>In the above case, the accelerator was defined as the character <tt>^M<\/tt>, which is shorthand for Ctrl+M, or character code 13. There are multiple ways to enter that character code. You could type <kbd>Ctrl<\/kbd>+<kbd>M<\/kbd> on the keyboard, or you could press the <kbd>Enter<\/kbd> key.<\/p>\n<p>If you want the accelerator to trigger only for the case of <kbd>Ctrl<\/kbd>+<kbd>M<\/kbd>, then you want to define a virtual key accelerator, not a character accelerator.<\/p>\n<pre>IDA_MAIN ACCELERATORS\r\nBEGIN\r\n\"M\", IDM_MUMBLE, CONTROL, VIRTKEY\r\nEND\r\n<\/pre>\n<p>Virtual key accelerators trigger only when the specified keys are pressed. In our case, we want the <kbd>M<\/kbd> virtual key in combination with the <kbd>CTRL<\/kbd> key.<\/p>\n<p>Conversely, if you want the accelerator to trigger only for the <kbd>Enter<\/kbd> key, you would specify that key as a virtual key.<\/p>\n<pre>IDA_MAIN ACCELERATORS\r\nBEGIN\r\nVK_RETURN, IDM_MUMBLE, VIRTKEY\r\nEND\r\n<\/pre>\n<p>There are two more key-to-control-character combinations that you may stumble across.<\/p>\n<ul>\n<li><kbd>Backspace<\/kbd> becomes the character <tt>^H<\/tt>.<\/li>\n<li><kbd>Tab<\/kbd> becomes the character <tt>^I<\/tt>.<\/li>\n<\/ul>\n<p>Technically, there is a third combination:<\/p>\n<ul>\n<li><kbd>Esc<\/kbd> becomes the character <tt>^[<\/tt>.<\/li>\n<\/ul>\n<p>However, the Resource Compiler does not accept <tt>\"^[\"<\/tt> as a control key, so you aren&#8217;t going to run into that one by mistake.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understanding the difference between keys and characters for accelerators.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-111908","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Understanding the difference between keys and characters for accelerators.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111908","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=111908"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111908\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=111908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=111908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=111908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}