{"id":112062,"date":"2026-02-13T07:00:00","date_gmt":"2026-02-13T15:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=112062"},"modified":"2026-02-13T10:17:52","modified_gmt":"2026-02-13T18:17:52","slug":"20260213-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20260213-00\/?p=112062","title":{"rendered":"How can I distinguish between the numeric keypad 0 and the top-row 0 in the <CODE>WM_<WBR>CHAR<\/CODE> message?"},"content":{"rendered":"<p>Last time, we looked at <a title=\"How can I distinguish between the numeric keypad 0 and the top-row 0 in the WM_KEY\u00adDOWN message?\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20260212-00\/?p=112059\"> how to distinguish the numeric keypad 0 and the top-row 0 in the <code>WM_<wbr \/>KEY\u00adDOWN<\/code> message<\/a>. We may as well look at the analogous table for <code>WM_<wbr \/>CHAR<\/code>.<\/p>\n<table style=\"border-collapse: collapse;\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n<tbody>\n<tr>\n<th>Event<\/th>\n<th>wParam<\/th>\n<th>Extended?<\/th>\n<\/tr>\n<tr>\n<td>Numpad0 with NumLock on<\/td>\n<td><tt>VK_0<\/tt><\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>Numpad0 with NumLock off<\/td>\n<td style=\"text-align: center;\" colspan=\"2\">(no <code>WM_CHAR<\/code>)<\/td>\n<\/tr>\n<tr>\n<td><kbd>Ins<\/kbd> key<\/td>\n<td style=\"text-align: center;\" colspan=\"2\">(no <code>WM_CHAR<\/code>)<\/td>\n<\/tr>\n<tr>\n<td>0 on top row<\/td>\n<td><tt>VK_0<\/tt><\/td>\n<td>0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>I got the name <code>VK_0<\/code> from this comment block in <tt>winuser.h<\/tt>.<\/p>\n<pre>\/*\r\n * VK_0 - VK_9 are the same as ASCII '0' - '9' (0x30 - 0x39)\r\n * 0x3A - 0x40 : unassigned\r\n * VK_A - VK_Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A)\r\n *\/\r\n<\/pre>\n<p>Uh-oh. The extended bit doesn&#8217;t distinguish between the two. They both show up as <code>VK_0<\/code>, non-extended.<\/p>\n<p>What changes is something not in the above table: The scan code.<\/p>\n<p>So let&#8217;s convert the scan code back to a virtual key.<\/p>\n<pre>auto vk_from_scan = MapVirtualKey((lParam &gt;&gt; 16) &amp; 0xFF, MAPVK_VSC_TO_VK);\r\n<\/pre>\n<table style=\"border-collapse: collapse;\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n<tbody>\n<tr>\n<th>Event<\/th>\n<th>wParam<\/th>\n<th>Extended?<\/th>\n<th><tt>vk_from_scan<\/tt><\/th>\n<\/tr>\n<tr>\n<td>Numpad0 with NumLock on<\/td>\n<td><tt>VK_0<\/tt><\/td>\n<td>0<\/td>\n<td><tt>VK_INSERT<\/tt><\/td>\n<\/tr>\n<tr>\n<td>Numpad0 with NumLock off<\/td>\n<td style=\"text-align: center;\" colspan=\"3\">(no <code>WM_CHAR<\/code>)<\/td>\n<\/tr>\n<tr>\n<td><kbd>Ins<\/kbd> key<\/td>\n<td style=\"text-align: center;\" colspan=\"3\">(no <code>WM_CHAR<\/code>)<\/td>\n<\/tr>\n<tr>\n<td>0 on top row<\/td>\n<td><tt>VK_0<\/tt><\/td>\n<td>0<\/td>\n<td><tt>VK_0<\/tt><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>So we can infer which zero was pressed by taking the scan code, mapping it to a virtual key, and seeing whether it&#8217;s the <kbd>Ins<\/kbd> key (from the numeric keypad) or the <kbd>0<\/kbd> key (from the top row).<\/p>\n<p>But wait, we&#8217;re not done yet.<\/p>\n<p>There are ways to type the character <tt>0<\/tt> without using the numeric keypad or the top row. For example, you can hold the <kbd>Alt<\/kbd> key and then type <kbd>4<\/kbd>,<kbd>8<\/kbd> on the numeric keypad, and that will type a <tt>0<\/tt>. I tried it out, and the <code>vk_from_scan<\/code> was <code>VK_<wbr \/>MENU<\/code>, which is the virtual key code for the <kbd>Alt<\/kbd> key. Another way of entering a <tt>0<\/tt> is by using an input method editor (IME). Or there might be a custom keyboard layout that generates a <tt>0<\/tt> through some wacky chord sequence.<\/p>\n<p>Therefore, if the <code>vk_<wbr \/>from_<wbr \/>scan<\/code> is neither <code>VK_<wbr \/>INSERT<\/code> nor <code>VK_0<\/code>, you have to conclude that the <tt>0<\/tt> was entered by some means other than the numeric keypad or the top row.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>See if it matches the scan code.<\/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-112062","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>See if it matches the scan code.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112062","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=112062"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112062\/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=112062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=112062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=112062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}