xinput_wrapper 0.7.0 → 0.8.0

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: af1558bd803a67895343a73b2001a42194b5402bc8998d410d9c388b4836a593
4
- data.tar.gz: 63e171df3280f2385b404f82673037a2a69e47e758be649253dc6701bc61a089
3
+ metadata.gz: 8bff9abfb50413d2ef185c472020cd348c53da5512b1f12d92ffbce10b491d2c
4
+ data.tar.gz: 4066ac4f9896ee680bff3a583bc1caf855c5bb17a43e40ff80aeaa4a9c01f263
5
5
  SHA512:
6
- metadata.gz: 1874c64eed6da4e726bc9e2e8ae755e0e7e3162cce593db5109aa344210b10f414c4917daecd8e188a28287c4a1d13188b23912e42680354adcc114714476e6b
7
- data.tar.gz: 9af8809d460ff318ff88fc6f49e310bff9ad612f8c800a9aceae0efe55d4a8f70f32cac93e704de837f6683cb09ef8a366b029d78283587bd1af6450b7246b33
6
+ metadata.gz: b8cd2b9b6c92418ed1d517d5f201b7e34e8ac7146ba8857d17b94638f4dd05eb626d8c75b1bd7afcc31ca475e7935302db2cb4015a75049a02fc843f3f278a9f
7
+ data.tar.gz: ce4b85f5cab6c0f613d0530c630ce227e15df0432e018b1aae15071484e7c72ef79708a21a771db7f5d50d2770aff051b4778f1d9ea9f4edfabdc4b927431459
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -31,10 +31,14 @@ class XInputWrapper
31
31
  # 10 = USB Optical Mouse (locally attached)
32
32
  # 11 = Microsoft Wired Keyboard 600 (locally attached)
33
33
  #
34
+
35
+ # keys - add the keys you want to be captured. If empty then
36
+ # all keys are captured.
37
+
34
38
  def initialize(device: nil, verbose: true, lookup: {}, debug: false,
35
- callback: nil )
39
+ callback: nil, keys: [] )
36
40
 
37
- @callback = callback
41
+ @callback, @keys = callback, keys
38
42
 
39
43
  # defaults to QWERTY keyboard layout
40
44
  @modifiers = {
@@ -100,6 +104,7 @@ class XInputWrapper
100
104
  }.merge(@modifiers).merge(lookup)
101
105
 
102
106
  @device, @verbose, @debug = device, verbose, debug
107
+ @mouse_pos = [0, 0]
103
108
 
104
109
  end
105
110
 
@@ -202,7 +207,8 @@ class XInputWrapper
202
207
  # type = 13 means a key has been pressed
203
208
  if type == RAWKEY_PRESS then
204
209
 
205
- if @modifiers.include? raw_keys.last or @modifiers.include? keycode then
210
+ if @modifiers.include? raw_keys.last or \
211
+ @modifiers.include? keycode then
206
212
  raw_keys << keycode
207
213
  end
208
214
 
@@ -224,10 +230,28 @@ class XInputWrapper
224
230
 
225
231
  puts key.to_s + ' key presssed' if @verbose
226
232
  name = "on_#{key}_key".to_sym
227
- method(name).call if self.protected_methods.include? name
233
+ puts 'name: ' + name.inspect if @debug
234
+
235
+ if private_methods.include? name and (@keys.empty? or \
236
+ @keys.include? key.to_sym) then
237
+ puts 'before method' if @debug
238
+ method(name).call
239
+ end
228
240
 
229
241
  keystring = ((key.length > 1 or key == ' ') ? "{%s}" % key : key)
230
- block_given? ? yield(keystring) : on_key_press(keystring, keycode)
242
+
243
+ if block_given? then
244
+
245
+ yield(keystring)
246
+
247
+ else
248
+
249
+ if @keys.empty? or @keys.include? key.to_sym then
250
+ on_key_press(keystring, keycode)
251
+ end
252
+
253
+ end
254
+
231
255
  @callback.on_keypress(keystring, keycode) if @callback
232
256
 
233
257
  end
@@ -240,9 +264,13 @@ class XInputWrapper
240
264
  if block_given? then
241
265
  yield(format_key(keys.last, keys[0..-2]))
242
266
  else
243
- on_key_press(keys.last, keycode, keys[0..-2])
244
- @callback.on_keypress(keys.last, keycode, keys[0..-2]) if @callback
267
+
268
+ if @keys.empty? or (!@keys.empty? and \
269
+ @keys.include? keys.last) then
270
+ on_key_press(keys.last, keycode, keys[0..-2])
271
+ end
245
272
  end
273
+ @callback.on_keypress(keys.last, keycode, keys[0..-2]) if @callback
246
274
 
247
275
  raw_keys = []
248
276
 
@@ -266,8 +294,14 @@ class XInputWrapper
266
294
  yield(format_key(key.to_s))
267
295
 
268
296
  else
269
- name = "on_#{key}_key".to_sym
270
- method(name).call if self.protected_methods.include? name
297
+ name = "on_#{key.to_s}_key".to_sym
298
+ puts 'calling method' if @debug
299
+
300
+ if private_methods.include? name and (@keys.empty? or \
301
+ @keys.include? key.to_sym) then
302
+ method(name).call #if self.methods.include? name
303
+ end
304
+
271
305
  on_key_press(key, keycode)
272
306
  @callback.on_keypress(key, keycode) if @callback
273
307
  end
@@ -302,10 +336,14 @@ class XInputWrapper
302
336
  end
303
337
  end
304
338
 
305
- protected
339
+ private
340
+
341
+ def message(s)
342
+ puts 'msg: ' + s
343
+ end
306
344
 
307
- def on_control_key()
308
- puts 'ctrl key pressed'
345
+ def on_ctrl_key()
346
+ message 'ctrl key pressed'
309
347
  end
310
348
 
311
349
  def on_key_press(key, keycode, modifier=nil)
@@ -360,20 +398,18 @@ class XInputWrapper
360
398
  def on_shift_key() end
361
399
  def on_super_key() end
362
400
 
363
- def on_f1_key() end
364
- def on_f2_key() end
365
- def on_f3_key() end
366
- def on_f4_key() end
367
- def on_f5_key() end
368
- def on_f6_key() end
369
- def on_f7_key() end
370
- def on_f8_key() end
371
- def on_f9_key() end
372
- def on_f10_key() end
373
- def on_f11_key() end
374
- def on_f12_key() end
375
-
376
- private
401
+ def on_f1_key() message 'f1' end
402
+ def on_f2_key() message 'f2' end
403
+ def on_f3_key() message 'f3' end
404
+ def on_f4_key() message 'f4' end
405
+ def on_f5_key() message 'f5' end
406
+ def on_f6_key() message 'f6' end
407
+ def on_f7_key() message 'f7' end
408
+ def on_f8_key() message 'f8' end
409
+ def on_f9_key() message 'f9' end
410
+ def on_f10_key() message 'f10' end
411
+ def on_f11_key() message 'f11' end
412
+ def on_f12_key() message 'f12' end
377
413
 
378
414
  def format_key(key, modifier=[])
379
415
 
@@ -382,6 +418,7 @@ class XInputWrapper
382
418
 
383
419
  end
384
420
 
421
+ def on_alt_key() message 'alt' end
385
422
  def on_leftcontrol_key() on_control_key() end
386
423
  def on_rightcontrol_key() on_control_key() end
387
424
  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.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  B//EUqLB2VKtMmcrYMc2FfbLwllNLY4TRq+/lgVLoDb7oLHsiggYSLZS6lPBIQj/
36
36
  YnYsDKwN5siDA79sB0fqq2ml
37
37
  -----END CERTIFICATE-----
38
- date: 2020-08-04 00:00:00.000000000 Z
38
+ date: 2020-08-25 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: c32
metadata.gz.sig CHANGED
Binary file