{"id":337,"date":"2020-12-13T16:15:15","date_gmt":"2020-12-13T20:15:15","guid":{"rendered":"http:\/\/blog.labhackers.com\/?p=337"},"modified":"2020-12-13T16:15:15","modified_gmt":"2020-12-13T20:15:15","slug":"psychopy3-psychhid-based-keyboard-api","status":"publish","type":"post","link":"https:\/\/blog.labhackers.com\/?p=337","title":{"rendered":"PsychoPy3 PsychHID based Keyboard API"},"content":{"rendered":"\n<p><sup>Originally posted March 20th, 2019.<\/sup><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"480\" src=\"https:\/\/blog.labhackers.com\/wp-content\/uploads\/2020\/12\/keyboard.Keyboard_allos.png\" alt=\"\" class=\"wp-image-426\" srcset=\"https:\/\/blog.labhackers.com\/wp-content\/uploads\/2020\/12\/keyboard.Keyboard_allos.png 640w, https:\/\/blog.labhackers.com\/wp-content\/uploads\/2020\/12\/keyboard.Keyboard_allos-300x225.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Background<\/h2>\n\n\n\n<p>In&nbsp;<a href=\"http:\/\/blog.labhackers.com\/?p=285\" target=\"_blank\" rel=\"noreferrer noopener\">an earlier post<\/a>&nbsp;we used a&nbsp;<a href=\"https:\/\/www.labhackers.com\/millikey.html\" target=\"_blank\" rel=\"noreferrer noopener\">MilliKey response box<\/a>&nbsp;to test the time stamping accuracy of three different Python accessible keyboard event APIs when receiving 1000 Hz MilliKey USB keyboard events:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>psychopy.event.getKeys()<\/li><li>psychopy.iohub\u2026keyboard.getPresses()<\/li><li>Psychtoolbox Python PsychHID()<\/li><\/ul>\n\n\n\n<p>and found that Psychtoolbox PsychHID Python interface provided the most accurate keyboard event time stamps across all three OS\u2019es tested, particularly for macOS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">PsychoPy3 keyboard.Keyboard<\/h2>\n\n\n\n<p>In this post we use the MilliKey response box to test the&nbsp;<a href=\"https:\/\/github.com\/psychopy\/psychopy\" target=\"_blank\" rel=\"noreferrer noopener\">latest development version<\/a>&nbsp;of&nbsp;<a href=\"https:\/\/www.psychopy.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">PsychoPy3&nbsp;<\/a>and the new keyboard event handling module added by Jon Pierce, psychopy.hardware.keyboard.Keyboard.<\/p>\n\n\n\n<p>psychopy.hardware. keyboard.Keyboard uses the Psychtoolbox PsychHID Python interface to provide accurate cross platform 1000 Hz keyboard event time stamping.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Results<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">psychopy.hardware. keyboard.Keyboard<\/h3>\n\n\n\n<p>PsychoPy3\u2019s psychopy.hardware. keyboard.Keyboard module takes full advantage of the PsychHID engine to provide accurate 1000 Hz MilliKey keyboard event time stamping on Windows, Linux, and macOS.&nbsp;<strong>Average event latency is ~1 msec across all operating systems.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"480\" src=\"https:\/\/blog.labhackers.com\/wp-content\/uploads\/2020\/12\/keyboard.Keyboard_allos-1.png\" alt=\"\" class=\"wp-image-427\" srcset=\"https:\/\/blog.labhackers.com\/wp-content\/uploads\/2020\/12\/keyboard.Keyboard_allos-1.png 640w, https:\/\/blog.labhackers.com\/wp-content\/uploads\/2020\/12\/keyboard.Keyboard_allos-1-300x225.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p>Very nice.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Comparision<\/h2>\n\n\n\n<p>In comparison, lets look at the performance of other PsychoPy keyboard event APIs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">psychopy.iohub..keyboard.getPresses()<\/h3>\n\n\n\n<p>Python3 psychopy.iohub keyboard event timing is not as consistent across operating systems. On Windows, and in particular Linux, iohub comes close to matching the performance of PsychHID, but macOS causes extra delay compared to other operating systems.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"480\" src=\"https:\/\/blog.labhackers.com\/wp-content\/uploads\/2020\/12\/iohub_allos.png\" alt=\"\" class=\"wp-image-428\" srcset=\"https:\/\/blog.labhackers.com\/wp-content\/uploads\/2020\/12\/iohub_allos.png 640w, https:\/\/blog.labhackers.com\/wp-content\/uploads\/2020\/12\/iohub_allos-300x225.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">psychopy.event.getKeys()<\/h3>\n\n\n\n<p>Results for psychopy.event.getKeys() are similarly poor across operating systems. Remember that in this test keyboard events were being created during calls to win.flip(). The timing results show how big of an impact this has on time stamping error when a 60Hz monitor is used.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"480\" src=\"https:\/\/blog.labhackers.com\/wp-content\/uploads\/2020\/12\/getKeys_allos.png\" alt=\"\" class=\"wp-image-429\" srcset=\"https:\/\/blog.labhackers.com\/wp-content\/uploads\/2020\/12\/getKeys_allos.png 640w, https:\/\/blog.labhackers.com\/wp-content\/uploads\/2020\/12\/getKeys_allos-300x225.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/figure>\n\n\n\n<p>Happy Hacking!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Originally posted March 20th, 2019. Background In&nbsp;an earlier post&nbsp;we used a&nbsp;MilliKey response box&nbsp;to test the time stamping accuracy of three different Python accessible keyboard event APIs when receiving 1000 Hz MilliKey USB keyboard events: psychopy.event.getKeys() psychopy.iohub\u2026keyboard.getPresses() Psychtoolbox Python PsychHID() and found that Psychtoolbox PsychHID Python interface provided the most accurate keyboard event time stamps across&hellip; <a class=\"more-link\" href=\"https:\/\/blog.labhackers.com\/?p=337\">Continue reading <span class=\"screen-reader-text\">PsychoPy3 PsychHID based Keyboard API<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[17,4],"tags":[16,8,18,10,14],"class_list":["post-337","post","type-post","status-publish","format-standard","hentry","category-keyboard-event-timing","category-millikey-response-box","tag-keyboard-events","tag-millikey","tag-psychopy","tag-python","tag-timing","entry"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/blog.labhackers.com\/index.php?rest_route=\/wp\/v2\/posts\/337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.labhackers.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.labhackers.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.labhackers.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.labhackers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=337"}],"version-history":[{"count":4,"href":"https:\/\/blog.labhackers.com\/index.php?rest_route=\/wp\/v2\/posts\/337\/revisions"}],"predecessor-version":[{"id":433,"href":"https:\/\/blog.labhackers.com\/index.php?rest_route=\/wp\/v2\/posts\/337\/revisions\/433"}],"wp:attachment":[{"href":"https:\/\/blog.labhackers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.labhackers.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.labhackers.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}