{"id":12553,"date":"2010-10-12T07:00:00","date_gmt":"2010-10-12T14:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2010\/10\/12\/why-are-the-keyboard-scan-codes-for-digits-off-by-one\/"},"modified":"2010-10-12T07:00:00","modified_gmt":"2010-10-12T14:00:00","slug":"why-are-the-keyboard-scan-codes-for-digits-off-by-one","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20101012-00\/?p=12553\/","title":{"rendered":"Why are the keyboard scan codes for digits off by one?"},"content":{"rendered":"<p>\nIn\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/michkap\/archive\/2010\/10\/08\/10073124.aspx\">\n<i>Off by one what, exactly?<\/i><\/a>,\nmy colleague\n<a HREf=\"http:\/\/blogs.msdn.com\/b\/michkap\/\">Michael Kaplan<\/a>\nwrote\n<\/p>\n<blockquote CLASS=\"q\"><p>\nAnd this decision long ago that caused the scan codes to not line up\nfor these digits when they could have&#8230;\n<\/p><\/blockquote>\n<p>\nThe word that struck me there was &#8220;decision&#8221;.\n<\/p>\n<p>\nBecause it wasn&#8217;t a &#8220;decision&#8221; to make the scan codes almost-but-not-quite\nline up with digits.\nIt was just a coincidence.\n<\/p>\n<p>\nIf you look at the scan code table from Michael&#8217;s article\n<\/p>\n<p>\n<img SRC=\"https:\/\/web.archive.org\/web\/20101015045801im_\/http:\/\/www.trigeminal.com\/images\/scancodes.png\" WIDTH=\"700\" HEIGHT=\"228\">\n<\/p>\n<p>\nyou can see stretches of consecutive scan codes,\nbroken up by weird places where the consecutive pattern is\nviolated.\nThe weirdness makes more sense when you look at the original\nIBM PC XT keyboard:\n<\/p>\n<table BORDER=\"1\" CELLPADDING=\"3\" STYLE=\"border-collapse: collapse;border: solid .75pt black;text-align: center\">\n<tr>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">01<\/font><br \/>Esc<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">02<\/font><br \/>1<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">03<\/font><br \/>2<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">04<\/font><br \/>3<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">05<\/font><br \/>4<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">06<\/font><br \/>5<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">07<\/font><br \/>6<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">08<\/font><br \/>7<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">09<\/font><br \/>8<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">0A<\/font><br \/>9<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">0B<\/font><br \/>0<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">0C<\/font><br \/>&minus;<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">0D<\/font><br \/>=<\/td>\n<td COLSPAN=\"6\" STYLE=\"width: 6ex\"><font SIZE=\"-1\">0E<\/font><br \/>&larr;<\/td>\n<\/tr>\n<tr>\n<td COLSPAN=\"5\" STYLE=\"width: 5ex\"><font SIZE=\"-1\">0F<\/font><br \/>&#x21e5;<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">10<\/font><br \/>Q<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">11<\/font><br \/>W<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">12<\/font><br \/>E<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">13<\/font><br \/>R<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">14<\/font><br \/>T<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">15<\/font><br \/>Y<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">16<\/font><br \/>U<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">17<\/font><br \/>I<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">18<\/font><br \/>O<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">19<\/font><br \/>P<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">1A<\/font><br \/>[<\/td>\n<td COLSPAN=\"5\" STYLE=\"width: 5ex\"><font SIZE=\"-1\">1B<\/font><br \/>]<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\" ROWSPAN=\"2\"><font SIZE=\"-1\">1C<\/font><br \/>&#x21b2;<\/td>\n<\/tr>\n<tr>\n<td COLSPAN=\"6\" STYLE=\"width: 6ex\"><font SIZE=\"-1\">1D<\/font><br \/>Ctrl<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">1E<\/font><br \/>A<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">1F<\/font><br \/>S<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">20<\/font><br \/>D<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">21<\/font><br \/>F<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">22<\/font><br \/>G<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">23<\/font><br \/>H<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">24<\/font><br \/>J<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">25<\/font><br \/>K<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">26<\/font><br \/>L<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">27<\/font><br \/>;<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">28<\/font><br \/>&#8216;<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">29<\/font><br \/>`<\/td>\n<\/tr>\n<tr>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">2A<\/font><br \/>&#x21e7;<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">2B<\/font><br \/>\\<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">2C<\/font><br \/>Z<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">2D<\/font><br \/>X<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">2E<\/font><br \/>C<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">2F<\/font><br \/>V<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">30<\/font><br \/>B<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">31<\/font><br \/>N<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">32<\/font><br \/>M<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">33<\/font><br \/>,<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">34<\/font><br \/>.<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">35<\/font><br \/>\/<\/td>\n<td COLSPAN=\"6\" STYLE=\"width: 6ex\"><font SIZE=\"-1\">36<\/font><br \/>&#x21e7;<\/td>\n<td COLSPAN=\"4\" STYLE=\"width: 4ex\"><font SIZE=\"-1\">37<\/font><br \/>*<\/td>\n<\/tr>\n<tr>\n<td COLSPAN=\"5\" STYLE=\"width: 5ex\"><font SIZE=\"-1\">38<\/font><br \/>Alt<\/td>\n<td COLSPAN=\"40\" STYLE=\"width: 40ex\"><font SIZE=\"-1\">39<\/font><br \/>Space<\/td>\n<td COLSPAN=\"9\" STYLE=\"width: 9ex\"><font SIZE=\"-1\">3A<\/font><br \/>Caps<\/td>\n<\/tr>\n<\/table>\n<p>\nWith this presentation, it becomes clearer how scan codes were assigned:\nThey simply started at 01 and continued through the keyboard\nin English reading order.\n(Scan code 00 is an error code indicating keyboard buffer overflow.)\nThe reason for the keyboard scan code being off-by-one from the\ndigits is merely due to the fact that there was one key to the\nleft of the digits.\nIf there were two keys to the left of the digits, they would have\nbeen off by two.\n<\/p>\n<p>\nOf course, if the original keyboard designers had\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2010\/10\/04\/10070943.aspx\">\nstarted counting from the lower left corner,\nlike all right-thinking mathematically-inclined people<\/a>,\nthen this sort-of-coincidence would never have happened.\nThe scan codes for the digits would have been\n2E through 37, and nobody would have thought anything of it.\n<\/p>\n<p>\nIt&#8217;s a testament to the human brain&#8217;s\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2003\/08\/25\/54700.aspx\">\ndesire to find patterns and determine a reason for them<\/a>\nthat what is really just a coincidence\ngets interpreted as some sort of conspiracy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What, they were digits?<\/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":[2],"class_list":["post-12553","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history"],"acf":[],"blog_post_summary":"<p>What, they were digits?<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/12553","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=12553"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/12553\/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=12553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=12553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=12553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}