{"id":267,"date":"2014-10-13T22:58:39","date_gmt":"2014-10-13T21:58:39","guid":{"rendered":"http:\/\/www.buschtrommel.net\/?p=267"},"modified":"2014-10-13T22:58:39","modified_gmt":"2014-10-13T21:58:39","slug":"mausabfragen-mit-dem-raspberry-pi","status":"publish","type":"post","link":"https:\/\/www.buschtrommel.net\/?p=267","title":{"rendered":"Mausabfragen mit dem Raspberry PI"},"content":{"rendered":"<p>Mit einer umgebauten Maus will ich den Raspberry PI als Radio steuern. Die Maus soll dabei direct abgegriffen werden. Hier ein paar Codeschnipsel wie das geht:<\/p>\n<p>&nbsp;<\/p>\n<p><code><\/p>\n<p>#!\/usr\/bin\/python<br \/>\nimport struct<br \/>\nimport time<br \/>\nimport sys<br \/>\nimport select<\/p>\n<p>infile_path = \"\/dev\/input\/event\" + (sys.argv[1] if len(sys.argv) &gt; 1 else \"0\")<\/p>\n<p>#long int, long int, unsigned short, unsigned short, unsigned int<br \/>\nFORMAT = 'llHHI'<br \/>\nEVENT_SIZE = struct.calcsize(FORMAT)<\/p>\n<p>#open file in binary mode<br \/>\nin_file = open(infile_path, \"rb\")<\/p>\n<p>event = in_file.read(EVENT_SIZE)<\/p>\n<p>while event:<br \/>\n(tv_sec, tv_usec, type, code, value) = struct.unpack(FORMAT, event)<\/p>\n<p>if type == 1 and code==273 and value==1:<br \/>\nprint(\"Key Rechts\")<\/p>\n<p>if type == 1 and code==272 and value==1:<br \/>\nprint(\"Key links\")<\/p>\n<p>if type == 1 and code==274 and value==1:<br \/>\nprint(\"RadKlick\");<\/p>\n<p>if type == 2 and code==8 and value ==1:<br \/>\n# swallow identical events directly after the existing one<br \/>\nwhile (in_file in select.select([in_file], [], [], 0.1)[0]):<br \/>\n#print(\"in while\")<br \/>\nevent = in_file.read(EVENT_SIZE)<br \/>\nprint(\"Scrollup\")<\/p>\n<p>if type == 2 and code==8 and value&gt;1:<br \/>\n# swallow identical events directly after the existing one<br \/>\nwhile (in_file in select.select([in_file], [], [], 0.3)[0]):<br \/>\n#print(\"in while\")<br \/>\nevent = in_file.read(EVENT_SIZE)<br \/>\nprint(\"Scrolldown\")<\/p>\n<p>event = in_file.read(EVENT_SIZE)<br \/>\n#print(\"gug\")<\/p>\n<p>in_file.close()<\/p>\n<p><\/code><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mit einer umgebauten Maus will ich den Raspberry PI als Radio steuern. Die Maus soll dabei direct abgegriffen werden. Hier ein paar Codeschnipsel wie das geht: &nbsp; #!\/usr\/bin\/python import struct import time import sys import select infile_path = &#8222;\/dev\/input\/event&#8220; + (sys.argv[1] if len(sys.argv) &gt; 1 else &#8222;0&#8220;) #long int, long int, unsigned short, unsigned short, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.buschtrommel.net\/index.php?rest_route=\/wp\/v2\/posts\/267"}],"collection":[{"href":"https:\/\/www.buschtrommel.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.buschtrommel.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.buschtrommel.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.buschtrommel.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=267"}],"version-history":[{"count":2,"href":"https:\/\/www.buschtrommel.net\/index.php?rest_route=\/wp\/v2\/posts\/267\/revisions"}],"predecessor-version":[{"id":269,"href":"https:\/\/www.buschtrommel.net\/index.php?rest_route=\/wp\/v2\/posts\/267\/revisions\/269"}],"wp:attachment":[{"href":"https:\/\/www.buschtrommel.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.buschtrommel.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.buschtrommel.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}