device_input 0.2.1.1 → 0.3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -12
- data/VERSION +1 -1
- data/bin/evdump +40 -0
- data/lib/device_input.rb +6 -8
- metadata +3 -3
- data/bin/devsniff +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00eb69decfeb19916bef79e450c1971bf73876a6
|
4
|
+
data.tar.gz: 101794e4db2d8cb6e3550c1f515e92a54b8fd526
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed04d353a1879d3a3cde29514efd6f97b15411b0f114c9638a7d56facd99cbc1213bcb3c75f014377d1971748258231b71364c6f3b831e343a7265b72d369aa6
|
7
|
+
data.tar.gz: 8675d1bb76626cd90924aa62abb017b7779ce114effa82619bd24235044e3d478f971b9c0c163f51b42f28eb2a5d36c102844eaac64a26f67c12081ac71e18f3
|
data/README.md
CHANGED
@@ -66,7 +66,7 @@ $ gem install device_input # sudo as necessary
|
|
66
66
|
|
67
67
|
Or, if using [Bundler](http://bundler.io/), add to your `Gemfile`:
|
68
68
|
```ruby
|
69
|
-
gem 'device_input', '~> 0.
|
69
|
+
gem 'device_input', '~> 0.3'
|
70
70
|
```
|
71
71
|
|
72
72
|
# Usage
|
@@ -74,7 +74,7 @@ gem 'device_input', '~> 0.1'
|
|
74
74
|
## Executable
|
75
75
|
|
76
76
|
```shell
|
77
|
-
$
|
77
|
+
$ evdump /dev/input/event0 # sudo as necessary
|
78
78
|
```
|
79
79
|
|
80
80
|
When the `f` key is pressed:
|
@@ -96,7 +96,7 @@ EV_SYN:SYN_REPORT:0
|
|
96
96
|
|
97
97
|
How about pretty mode?
|
98
98
|
```shell
|
99
|
-
$ sudo
|
99
|
+
$ sudo cat /dev/input/event0 | evdump --print pretty
|
100
100
|
|
101
101
|
# f
|
102
102
|
|
@@ -110,7 +110,7 @@ $ sudo devsniff /dev/input/event0 pretty
|
|
110
110
|
|
111
111
|
We can pull off the labels and go raw:
|
112
112
|
```shell
|
113
|
-
$ sudo
|
113
|
+
$ sudo cat /dev/input/event0 | evdump --print raw
|
114
114
|
|
115
115
|
# f
|
116
116
|
|
@@ -124,7 +124,7 @@ $ sudo devsniff /dev/input/event0 raw
|
|
124
124
|
|
125
125
|
Fulfill your hacker-matrix fantasies:
|
126
126
|
```shell
|
127
|
-
$ sudo
|
127
|
+
$ sudo cat /dev/input/event0 | evdump --print hex
|
128
128
|
|
129
129
|
# f
|
130
130
|
|
@@ -141,10 +141,12 @@ $ sudo devsniff /dev/input/event0 hex
|
|
141
141
|
```ruby
|
142
142
|
require 'device_input'
|
143
143
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
144
|
+
File.open('/dev/input/event0', 'r') do |dev|
|
145
|
+
# this loops forever and blocks waiting for input
|
146
|
+
DeviceInput.read_loop(dev) do |event|
|
147
|
+
puts event
|
148
|
+
# break if event.time > start + 30
|
149
|
+
end
|
148
150
|
end
|
149
151
|
```
|
150
152
|
|
@@ -157,11 +159,11 @@ An event has:
|
|
157
159
|
* `#value`: Fixnum (signed) from `#data`
|
158
160
|
|
159
161
|
You will probably want to write your own read loop for your own project.
|
160
|
-
[`DeviceInput.
|
162
|
+
[`DeviceInput.read_loop`](lib/device_input.rb#L102) is very simple and can
|
161
163
|
easily be rewritten outside of this project's namespace and adapted for your
|
162
164
|
needs.
|
163
165
|
|
164
|
-
#
|
166
|
+
# Background
|
165
167
|
|
166
168
|
## Kernel docs
|
167
169
|
|
@@ -206,7 +208,7 @@ What's a [`__kernel_time_t`](https://git.kernel.org/cgit/linux/kernel/git/torval
|
|
206
208
|
```
|
207
209
|
typedef long __kernel_long_t;
|
208
210
|
# ...
|
209
|
-
typedef __kernel_long_t
|
211
|
+
typedef __kernel_long_t __kernel_suseconds_t;
|
210
212
|
# ...
|
211
213
|
typedef __kernel_long_t __kernel_time_t;
|
212
214
|
```
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0.2
|
data/bin/evdump
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'device_input'
|
4
|
+
require 'slop'
|
5
|
+
|
6
|
+
opts = Slop.parse do |o|
|
7
|
+
o.banner = "evdump [OPTIONS] [DEVICE]"
|
8
|
+
o.string '-p', '--print', 'pretty|raw|hex'
|
9
|
+
o.on '-h', '--help' do
|
10
|
+
puts o
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def opts.error(msg = nil)
|
16
|
+
puts self
|
17
|
+
puts "ERROR: #{msg}" if msg
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
|
21
|
+
case opts[:print]
|
22
|
+
when 'pretty', 'raw', 'hex'
|
23
|
+
print_meth = opts[:print]
|
24
|
+
else
|
25
|
+
print_meth = 'to_s'
|
26
|
+
end
|
27
|
+
|
28
|
+
if $stdin.tty?
|
29
|
+
device = opts.arguments.shift
|
30
|
+
opts.error "Please specify an input device file" unless device
|
31
|
+
opts.error "#{device} is not a character device" unless File.chardev? device
|
32
|
+
opts.error "#{device} is not readable" unless File.readable? device
|
33
|
+
device = File.new(device, 'r')
|
34
|
+
else
|
35
|
+
device = $stdin
|
36
|
+
end
|
37
|
+
|
38
|
+
DeviceInput.read_loop(device) { |event|
|
39
|
+
puts event.send(print_meth)
|
40
|
+
}
|
data/lib/device_input.rb
CHANGED
@@ -99,14 +99,12 @@ module DeviceInput
|
|
99
99
|
alias_method :hex, RUBY23 ? :ruby23_hex : :to_s
|
100
100
|
end
|
101
101
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
yield Event.new(data)
|
109
|
-
}
|
102
|
+
def self.read_loop(io)
|
103
|
+
loop {
|
104
|
+
bytes = io.read(Event::BYTE_LENGTH)
|
105
|
+
break unless (bytes and bytes.length == Event::BYTE_LENGTH)
|
106
|
+
data = Event.decode(bytes)
|
107
|
+
yield Event.new(data)
|
110
108
|
}
|
111
109
|
end
|
112
110
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: device_input
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Hull
|
@@ -29,13 +29,13 @@ description: |
|
|
29
29
|
No dependencies. Ruby 2+ required
|
30
30
|
email:
|
31
31
|
executables:
|
32
|
-
-
|
32
|
+
- evdump
|
33
33
|
extensions: []
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
36
|
- README.md
|
37
37
|
- VERSION
|
38
|
-
- bin/
|
38
|
+
- bin/evdump
|
39
39
|
- lib/device_input.rb
|
40
40
|
- lib/device_input/compat.rb
|
41
41
|
- lib/device_input/labels.rb
|
data/bin/devsniff
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'device_input'
|
4
|
-
|
5
|
-
device = ARGV.shift || '/dev/input/event0'
|
6
|
-
mode = (ARGV.shift || 'normal').downcase
|
7
|
-
|
8
|
-
if !File.readable?(device)
|
9
|
-
puts "#{device} cannot be read. Perhaps you need to sudo?"
|
10
|
-
exit 1
|
11
|
-
end
|
12
|
-
|
13
|
-
case mode
|
14
|
-
when 'normal'
|
15
|
-
mode = 'to_s'
|
16
|
-
when 'bytes' # legacy
|
17
|
-
mode = 'hex'
|
18
|
-
when 'pretty', 'raw', 'hex'
|
19
|
-
# ok
|
20
|
-
else
|
21
|
-
raise "unsupported mode: #{mode}"
|
22
|
-
end
|
23
|
-
|
24
|
-
DeviceInput.read_from(device) { |event|
|
25
|
-
puts event.send(mode)
|
26
|
-
}
|