{"id":94385,"date":"2016-09-26T07:00:00","date_gmt":"2016-09-26T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=94385"},"modified":"2019-03-13T11:07:12","modified_gmt":"2019-03-13T18:07:12","slug":"20160926-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20160926-00\/?p=94385","title":{"rendered":"It says that I should use USB usage page 1 and usage 6 to get raw keyboard data, but what if I have a PS\/2 keyboard?"},"content":{"rendered":"<p>Some time ago, I wrote about raw input and noted that if you want to receive raw keyboard input, you set the usage page to 1 and the usage to 6, noting that these numbers come from the USB HID specification. Commenter onodera asks, &#8220;<a HREF=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/#comment-1255025\">Does this work for PS\/2 input devices as well<\/a>?&#8221; <\/p>\n<p>Let&#8217;s try it. I happen to have a laptop within easy reach, so I plugged in an external USB wireless keyboard, then went to Device Manager. It says <\/p>\n<div STYLE=\"border: solid 1px black;width: 20em\">\n<div>&#x2335; &#x2328; Keyboards<\/div>\n<div STYLE=\"padding-left: 3em\">&#x2328; Standard PS\/2 Keyboard<\/div>\n<div STYLE=\"padding-left: 3em\">&#x2328; Wireless Keyboard Filter Device<\/div>\n<\/p><\/div>\n<p>Then I ran <a HREF=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/\">the sample raw keyboard input program from the same article<\/a> and pressed the space bar a few times on the external USB wireless keyboard, then the space bar a few times on the built-in PS\/2 keyboard: <\/p>\n<pre>\n04E00817, msg=0100, vk=0020, scanCode=39, press\n04E00817, msg=0101, vk=0020, scanCode=39, release\n04E00817, msg=0100, vk=0020, scanCode=39, press\n04E00817, msg=0101, vk=0020, scanCode=39, release\n04E00817, msg=0100, vk=0020, scanCode=39, press\n04E00817, msg=0101, vk=0020, scanCode=39, release\n0001003D, msg=0100, vk=0020, scanCode=39, press\n0001003D, msg=0101, vk=0020, scanCode=39, release\n0001003D, msg=0100, vk=0020, scanCode=39, press\n0001003D, msg=0101, vk=0020, scanCode=39, release\n0001003D, msg=0100, vk=0020, scanCode=39, press\n0001003D, msg=0101, vk=0020, scanCode=39, release\n<\/pre>\n<p>The entries from device <code>04E00817<\/code> are from the external USB wireless keyboard. The entries from device <code>0001003D<\/code> are from the built-in PS\/2 keyboard. <\/p>\n<p>So there you go: It works even for PS\/2 keyboards. <\/p>\n<p>The fact that the input is described in terms of HID usage pages and HID usages is just a convenient way of expressing what kind of input you want, because it generalizes in the obvious way to to HID devices. Non-HID devices are mapped to the corresponding HID usages. <\/p>\n<p><b>Bonus chatter<\/b>: Raw input also captures synthesized input. Here&#8217;s the result after performing a <code>Send&shy;Input<\/code> to simulate pressing the space bar: <\/p>\n<pre>\n00000000, msg=0100, vk=0020, scanCode=39, press\n00000000, msg=0101, vk=0020, scanCode=39, release\n<\/pre>\n<p>Notice that this was a completely synthetic keypress, but it showed up anyway, despite not having come from a USB device (or indeed any device at all). Note also that the device handle is null. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The numbers came from the USB HID specification, but that doesn&#8217;t require the keyboard to be USB.<\/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-94385","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The numbers came from the USB HID specification, but that doesn&#8217;t require the keyboard to be USB.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/94385","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=94385"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/94385\/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=94385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=94385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=94385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}