README.md in device_input-0.1.0.1 vs README.md in device_input-0.1.1.1

- old
+ new

@@ -20,11 +20,11 @@ Since these are C structs (analagous to a binary message), we need to be able to delimit individual messages and decode them. We can't simply read a byte at a time and try to make sense of it. In fact, on my system, `/dev/input/event0` refuses any read that is not a multiple of the struct / message size, so we need to know the message size before even attempting a -read(), without even a decode(). +`read()`, let alone a `decode()`. To determine the message size, we need to know the data structure. For a long time, it was pretty simple: events are 16 bytes: * timestamp - 8 bytes @@ -32,12 +32,13 @@ * code - 2 bytes * value - 4 bytes However, this is only true for 32-bit platforms. On 64-bit platforms, event timestamps became 16 bytes, increasing the size of events from 16 to 24 bytes. -This is because a timestamp is defined (ultimately) as two `long`s, and -`long`s are bigger on 64-bit platforms. It's easy to remember: +This is because a timestamp is defined (ultimately) as two `long`s, and as +everyone knows, two longs don't make a light. No, wait -- it's that `long`s +are bigger on 64-bit platforms. It's easy to remember: * 32-bit platform: 32-bit `long` (4 bytes) * 64-bit platform: 64-bit `long` (8 bytes) `read(/dev/input/event0, 16)` will fail on a 64-bit machine. @@ -48,52 +49,98 @@ encoded values to friendly strings for display, and provides both library and executable code to assist in examining kernel input events. # Installation -Requirements: Ruby >= 2.0 +**REQUIREMENTS** -Dependencies: none +* Ruby >= 2.0 +**DEPENDENCIES** + +* none + Install the gem: -``` +```shell $ gem install device_input # sudo as necessary ``` Or, if using [Bundler](http://bundler.io/), add to your `Gemfile`: +```ruby +gem 'device_input', '~> 0.1' ``` -gem 'device_input', '~> 0.0' -``` # Usage ## Executable -``` +```shell $ sudo devsniff /dev/input/event0 ``` When the `f` key is pressed: ``` -Misc:ScanCode:33 -Key:F:1 -Sync:Sync:0 +EV_MSC:ScanCode:33 +EV_KEY:F:1 +EV_SYN:SYN_REPORT:0 ``` -And released: +And released immediately (1=pressed, 0=released): ``` -Misc:ScanCode:33 -Key:F:1 -Sync:Sync:0 -Misc:ScanCode:33 -Key:F:0 -Sync:Sync:0 +EV_MSC:ScanCode:33 +EV_KEY:F:1 +EV_SYN:SYN_REPORT:0 +EV_MSC:ScanCode:33 +EV_KEY:F:0 +EV_SYN:SYN_REPORT:0 ``` -## Library +How about pretty mode? +```shell +$ sudo devsniff /dev/input/event0 pretty +# f + +2017-01-24 05:29:43.923 Misc:ScanCode:33 +2017-01-24 05:29:43.923 Key:F:1 +2017-01-24 05:29:43.923 Sync:Report:0 +2017-01-24 05:29:44.012 Misc:ScanCode:33 +2017-01-24 05:29:44.012 Key:F:0 +2017-01-24 05:29:44.012 Sync:Report:0 ``` + +We can pull off the labels and go raw: +```shell +$ sudo devsniff /dev/input/event0 raw + +# f + +4:4:33 +1:33:1 +0:0:0 +4:4:33 +1:33:0 +0:0:0 +``` + +Fulfill your hacker-matrix fantasies: +```shell +$ sudo devsniff /dev/input/event0 hex + +# f + +00000000588757bd 00000000000046ca 0004 0004 00000021 +00000000588757bd 00000000000046ca 0001 0021 00000001 +00000000588757bd 00000000000046ca 0000 0000 00000000 +00000000588757bd 000000000001a298 0004 0004 00000021 +00000000588757bd 000000000001a298 0001 0021 00000000 +00000000588757bd 000000000001a298 0000 0000 00000000 +``` + +## Library + +```ruby require 'device_input' # this loops forever and blocks waiting for input DeviceInput.read_from('/dev/input/event0') do |event| puts event @@ -108,11 +155,11 @@ * `#type`: String label, possibly `UNK-X` where X is the integer from `#data` * `#code`: String label, possibly `UNK-X-Y` where X and Y are from `#data` * `#value`: Fixnum (signed) from `#data` You will probably want to write your own read loop for your own project. -[`DeviceInput.read_from`](lib/device_input.rb#L111) is very simple and can +[`DeviceInput.read_from`](lib/device_input.rb#L100) is very simple and can easily be rewritten outside of this project's namespace and adapted for your needs. # Research @@ -211,7 +258,7 @@ # Acknowledgments * Inspired by https://github.com/prullmann/libdevinput (don't use it) - also the source of an early version of the - [event code labels](lib/device_input/codes.rb) + [event code labels](lib/device_input/labels.rb) * Thanks to al2o3-cr from #ruby on Freenode for feedback