xinput_wrapper 0.4.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 290701cfce88a11462cb860805bf014f6a6d0d366c7efaa4f2516423f1da87e1
4
- data.tar.gz: e82be2d004f3cfa0e358b162741c63058f9db8717e20d23e86c40e5e0ed5c179
3
+ metadata.gz: 7685727622dac6285e86dcf8095525fde1d6d129b7f210aed3ad2512138efdaa
4
+ data.tar.gz: f404c6286c440432f6b9ad26db6f8b6d36fc6e3ea0d6141baa439bf74c572e16
5
5
  SHA512:
6
- metadata.gz: 429ce14f3defe07737301513180730f9c406fb163cde5d9d0a064170f5b184ce64776c798b151fa049c33fb9a8d0d7eab2e72d92a48e7d248e3a792643be308f
7
- data.tar.gz: e67b773e97c10adfeb940e7e000f480c782ef975151526efaf6dfd6cce93f6f51008a40aa3b4d147501c64e2ce5f1122d42b503805336d6e722f19711287abbe
6
+ metadata.gz: 9ce3aaf5e903c982201b1ac8802b109f8388083b0e9f0de02454811e4300069a043b84a6bdf66db2604c70dec57c3a0564747d908beadf2b0216d49e4b9b0dd2
7
+ data.tar.gz: 9c2ae2545e99ba3d1a13789f5d7c24c11b15011f7a623169b1a7bfee9883a88091fcf9d182ead686df0564e9bdd384b0f8918f40f9a0374aca2f08c8a5533c1d
Binary file
data.tar.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- ���l�z1����SĖ ����8ntTD�,*t�������ښ��8�,��=��{�>"6F�X�&����v�8b��I���� t�6��8���1jL[ltkl�`���ivR�A"
2
- ��%��uO*d#9�־�c����v�vpS͟a�.��OG� յ� ?�IJ� ^��T������1�����H������A��be?��%<V���8���"����;��01�0?�Y� *h ��� C�ŋe�WYѻ��������0��U�/���"�����&� ���,a$Aa�T]��m<n=X��T@�/��)ur,��b׹Z�}�m{���3��p�n�o�������������G''~���3b���"<W�
1
+ r�&��� �(�B&C��S�����Y ���eJ{�� ��)s����c�=]y`r?�JG�h&�t&�X���gBQ;�:� ^/�u.m:����?�Bzy�$/� ?�زms�&M��g1XC'y@�DUk:V� �)T�5�K���L��i�d��6]"�}���ɭ��p[� ���U�\�����$YphU�c��Q���qQâA}�� K�ҡA��7z�����'��0N�K�k-
2
+ >:��&ŏ1�Y@H��#Z�U���U��~�@� ܠg��X���Hn ��x0q�Z�G�
@@ -2,13 +2,31 @@
2
2
 
3
3
  # file: xinput_wrapper.rb
4
4
 
5
+ # Captures keyboard or mouse events using program xinput.
6
+
7
+
8
+ # note: To display a list of xinput devices, run the
9
+ # xinput program without any options.
10
+
5
11
  require 'c32'
6
12
 
7
13
 
14
+ MOTION = 6
15
+ RAWKEY_PRESS = 13
16
+ RAWKEY_RELEASE = 14
17
+
18
+
8
19
  class XInputWrapper
9
20
  using ColouredText
10
21
 
11
- def initialize(device: '3', verbose: true, lookup: {}, debug: false )
22
+ # device list:
23
+ # 3 = Virtual core keyboard
24
+ # 4 = Virtual core XTEST pointer (active when using VNC)
25
+ # 5 = Virtual core XTEST keyboard (active when using VNC)
26
+ # 10 = USB Optical Mouse (locally attached)
27
+ # 11 = Microsoft Wired Keyboard 600 (locally attached)
28
+ #
29
+ def initialize(device: nil, verbose: true, lookup: {}, debug: false )
12
30
 
13
31
  # defaults to QWERTY keyboard layout
14
32
  @modifiers = {
@@ -28,8 +46,8 @@ class XInputWrapper
28
46
  31=>:i, 32=>:o, 33=>:p, 34=>:"[", 35=>:"]", 36=>:enter, 38=>:a, 39=>:s,
29
47
  40=>:d, 41=>:f, 42=>:g, 43=>:h, 44=>:j, 45=>:k, 46=>:l, 47=>:";",
30
48
  48=>:"'", 49=>nil, 52=>:z, 53=>:x, 54=>:c, 55=>:v, 56=>:b, 57=>:n,
31
- 58=>:m, 59=>:",", 60=>:".", 61=>:/, 65=>:" ",
32
- 9 => :escape,
49
+ 58=>:m, 59=>:",", 60=>:".", 61=>:/, 65=>:space,
50
+ 9 => :esc,
33
51
  66 => :capslock,
34
52
  67 => :f1,
35
53
  68 => :f2,
@@ -42,18 +60,18 @@ class XInputWrapper
42
60
  75 => :f9,
43
61
  76 => :f10,
44
62
  77 => :numlock,
45
- 78 => :scroll_lock,
63
+ 78 => :scrolllock,
46
64
  95 => :f11,
47
65
  96 => :f12,
48
- 107 => :print_screen,
66
+ 107 => :sysrq, # print_screen
49
67
  110 => :home,
50
- 111 => :up_arrow,
51
- 112 => :pgup,
52
- 113 => :left_arrow,
53
- 114 => :right_arrow,
54
- 115 => :end,
55
- 116 => :down_arrow,
56
- 117 => :pgdown,
68
+ 111 => :up, # arrow keys
69
+ 112 => :pageup,
70
+ 113 => :left, # arrow keys
71
+ 114 => :right, # arrow keys
72
+ 115 => :end,
73
+ 116 => :down, # arrow keys
74
+ 117 => :pagedown,
57
75
  121 => :mute,
58
76
  122 => :vol_down,
59
77
  123 => :vol_up,
@@ -78,27 +96,84 @@ class XInputWrapper
78
96
  end
79
97
 
80
98
  def listen()
81
-
99
+
82
100
  command = "xinput test-xi2 --root #{@device}"
83
101
 
84
102
  type = 0
85
103
  raw_keys = []
104
+ t1 = Time.now
105
+ lines = []
86
106
 
87
107
  IO.popen(command).each_line do |x|
88
108
 
89
- #print "GOT ", x
90
- raw_type = x[/EVENT type (\d+)/,1]
109
+ print "GOT ", x
110
+ if x[/EVENT type \d \(Motion\)/] and (Time.now > (t1 + 0.06125)) then
111
+
112
+ type = x[/EVENT type (\d+)/,1].to_i
113
+
114
+ r = lines.join[/^\s+root: (\d+\.\d{2}\/\d+\.\d{2})/,1]
115
+
116
+ if r then
117
+
118
+ x1, y1 = r.split('/').map(&:to_f)
119
+ puts "x1: %s y1: %s" % [x1, y1] if @debug
120
+ on_mousemove(x1, y1)
121
+ t1 = Time.now
122
+
123
+ end
124
+
125
+ lines = [x]
126
+
127
+ elsif x[/EVENT type \d+ \(RawKey(?:Release|Press)\)/]
91
128
 
92
- type = raw_type.to_i unless raw_type.nil?
93
- next unless type == 13 or type == 14
129
+ type = x[/EVENT type (\d+)/,1].to_i
130
+
131
+ lines = [x]
132
+
133
+ elsif type == MOTION or type == RAWKEY_PRESS or type == RAWKEY_RELEASE
134
+
135
+ lines << x
136
+
137
+ if x == "\n" then
138
+ case lines.first[/(?<=EVENT type )\d+/].to_i
139
+ when RAWKEY_PRESS
140
+
141
+ r = lines.join[/detail: (\d+)/,1]
142
+
143
+ keycode = r.to_i if r
144
+
145
+ type = lines.join[/EVENT type (\d+)/,1] .to_i
146
+
147
+ when RAWKEY_RELEASE
148
+
149
+ r = lines.join[/detail: (\d+)/,1]
150
+
151
+ keycode = r.to_i if r
152
+
153
+ type = lines.join[/EVENT type (\d+)/,1] .to_i
154
+
155
+ end
156
+
157
+
158
+ else
159
+ next
160
+ end
94
161
 
95
- keycode = x[/detail: (\d+)/,1].to_i
96
- next if keycode == 0
162
+ else
163
+ next
164
+ end
165
+
166
+ next unless keycode
167
+ puts 'keycode: ' + keycode.inspect if @debug
97
168
 
98
169
  # type = 13 means a key has been pressed
99
- if type == 13 then
170
+ if type == RAWKEY_PRESS then
100
171
 
101
- raw_keys << keycode
172
+ if @modifiers.include? raw_keys.last or @modifiers.include? keycode then
173
+ raw_keys << keycode
174
+ end
175
+
176
+ next if @modifiers.include? keycode
102
177
 
103
178
  puts 'raw_keys: ' + raw_keys.inspect if @debug
104
179
 
@@ -113,23 +188,54 @@ class XInputWrapper
113
188
  puts ('key: ' + key.inspect).debug if @debug
114
189
 
115
190
  if key then
191
+
116
192
  puts key.to_s + ' key presssed' if @verbose
117
193
  name = "on_#{key}_key".to_sym
118
194
  method(name).call if self.protected_methods.include? name
119
- on_key_press key, keycode
195
+
196
+ keystring = ((key.length > 1 or key == ' ') ? "{%s}" % key : key)
197
+ block_given? ? yield(keystring) : on_key_press(keystring, keycode)
198
+
120
199
  end
121
200
 
122
201
  else
123
202
 
124
203
  keys = raw_keys.map {|kc| @lookup[kc] }
125
204
  puts ('keys: ' + keys.inspect) if @debug
126
- on_key_press(keys.last, keycode, keys[0..-2])
205
+
206
+ if block_given? then
207
+ yield(format_key(keys.last, keys[0..-2]))
208
+ else
209
+ on_key_press(keys.last, keycode, keys[0..-2])
210
+ end
211
+
212
+ raw_keys = []
127
213
 
128
214
  end
129
215
 
130
216
 
131
217
 
132
- elsif type == 14
218
+ # a key has been released
219
+ elsif type == RAWKEY_RELEASE
220
+
221
+ # here we are only looking to detect a
222
+ # single modifier key press and release
223
+
224
+ key = @lookup[keycode]
225
+
226
+ unless raw_keys.empty? then
227
+ puts key.to_s + ' key presssed'
228
+
229
+ if block_given? then
230
+
231
+ yield(format_key(key.to_s))
232
+
233
+ else
234
+ name = "on_#{key}_key".to_sym
235
+ method(name).call if self.protected_methods.include? name
236
+ on_key_press(key, keycode)
237
+ end
238
+ end
133
239
 
134
240
  index = raw_keys.rindex(keycode)
135
241
  raw_keys.delete_at index if index
@@ -145,13 +251,21 @@ class XInputWrapper
145
251
  puts 'ctrl key pressed'
146
252
  end
147
253
 
148
- def on_key_press(key, keycode, modifier)
254
+ def on_key_press(key, keycode, modifier=nil)
149
255
 
150
256
  if @debug then
151
257
  puts ('key: ' + key.inspect).debug
152
258
  end
153
259
 
154
260
  end
261
+
262
+ def on_mousemove(x,y)
263
+
264
+ if @debug then
265
+ puts "on_mousemove() x: %s y: %s" % [x, y]
266
+ end
267
+
268
+ end
155
269
 
156
270
  def on_shift_key() end
157
271
  def on_super_key() end
@@ -171,6 +285,13 @@ class XInputWrapper
171
285
 
172
286
  private
173
287
 
288
+ def format_key(key, modifier=[])
289
+
290
+ modifier.any? ? "{%s}" % (modifier + [key.to_s]).join('+') \
291
+ : key.to_s
292
+
293
+ end
294
+
174
295
  def on_leftcontrol_key() on_control_key() end
175
296
  def on_rightcontrol_key() on_control_key() end
176
297
  def on_left_alt_key() on_alt_key() end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xinput_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -11,52 +11,52 @@ cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkwMjEwMTU1NTM1WhcN
15
- MjAwMjEwMTU1NTM1WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQD2pELS
17
- hfHN+He5s77qpnUO4j6GDr1B9PDIKqJDBz+kJCUGXsLzyHnKK8iIblXtETyIJn9F
18
- euzS6ohPh64xfBcKrnF7bSUAXsdC/PZIsNgvSp4Vuguxpe6wDHfaqBhV2KcOjGrP
19
- tnZRvJJHWBczBzMw+BAj0d5Zp5QZaVXDx3mN13t2j6tUncwLF3NYIlaFA7lN4uuV
20
- hiFyqlkk+ELO8eptDF5Wkel5ZjtALo9jOq04KAlImZ7cnFLD1zbAXWiKPyEvSAeL
21
- fGONgtYGEBwIKKeisGTucndYa1iwQOnFLjCixclGH+6+YInlbHUzl/JrFHSEXIYb
22
- 0jU2pHEu+xQlB2xdKiJF6Z/JWWabJ+hyMifxnyPYLW53QGV5fu2uAHDVUCplwhBW
23
- hOBeqmV8SCjX7aYytN7TiqO4Th2kP2tPLQqynFQ3ceNiTcjk1fkliXlv+lc8IFiS
24
- 25oy9Th0M3O7+rs11i1eeaAlvrZ0TWv5qFpJUrMB53UpndLxeroiPw/AzocCAwEA
25
- AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUQLWJJ/fU
26
- p6suCssS39/w2O9MQhUwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
14
+ YXN0ZXIvREM9amFtZXNyb2JlcnRzb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000000 Z
38
+ date: 2020-08-03 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: c32
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: '0.1'
47
44
  - - ">="
48
45
  - !ruby/object:Gem::Version
49
- version: 0.1.2
46
+ version: 0.2.0
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.2'
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - "~>"
55
- - !ruby/object:Gem::Version
56
- version: '0.1'
57
54
  - - ">="
58
55
  - !ruby/object:Gem::Version
59
- version: 0.1.2
56
+ version: 0.2.0
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.2'
60
60
  description:
61
61
  email: james@jamesrobertson.eu
62
62
  executables: []
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubygems_version: 3.0.1
86
+ rubygems_version: 3.0.3
87
87
  signing_key:
88
88
  specification_version: 4
89
89
  summary: A wrapper for the Linux utility xinput.
metadata.gz.sig CHANGED
Binary file