hidg0 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c57ae2c3727fbfefb5bc51a77d94646515464674474c30f803f6b797f0077b59
4
- data.tar.gz: 3fdc7dd21062adff5d6b975a8cf51ef5139b4f8939cd14f94a62f85736b5fde4
3
+ metadata.gz: ed5e0205a0076670f8d7daa2a0b3d2f435c201b39182761380863f1bc81a4751
4
+ data.tar.gz: d035c0286f3214cdf202245b2581e0de020079564b12ab0356dbee00a99896d4
5
5
  SHA512:
6
- metadata.gz: d7a7d93727b2a73b2eabd6910345fbdb898e63c984dde56a6b7b69806b4295dcb8129b95e8c6a91a10d36c4294cbe48c1a8d1b14ee566b997593ce3b1400d4dc
7
- data.tar.gz: c51c07fb6006ec43bcb9aa4fcf524856beec4f46d787e76a07eeeb7de94e84f41b7050d69f2e0b0735e7ceac928327328561588f19ebef71e8b705ba315be2a4
6
+ metadata.gz: a0b5ebbfbedfbf3ef8b3a1d036afa193ce715de54b0f1362e06dd6bf4a20305470a340e15e0cff59968bc50ce0c0e722600c1766c7ae62667208fe5e9abce7ec
7
+ data.tar.gz: 10ee00392668a9d176ffab716894b5522a4ddb8fad5e2f42d956716743ceb7d7f89336d87b0cf5c35c47e8bd5f282dc5505885e37b6e9ab73b8fc53b541a1c7a
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/hidg0.rb CHANGED
@@ -52,7 +52,8 @@ h = %i(right_gui rightalt rightshift rightctrl left_gui left_alt leftshift leftc
52
52
  reverse.map.with_index {|x,i| [x, (2 ** i)]}.to_h
53
53
 
54
54
  MODIFIERS = h.merge({shift: h[:leftshift], alt: h[:left_alt],
55
- ctrl: h[:leftctrl], control: h[:leftctrl]})
55
+ ctrl: h[:leftctrl], control: h[:leftctrl],
56
+ windows_key: h[:right_gui]})
56
57
 
57
58
  =begin
58
59
  byte1 byte2 byte3 bytes4...bytes8
@@ -102,6 +103,7 @@ KEYS = {
102
103
  :'0' => 39, # Keyboard 0 and )
103
104
  enter: 40, # Keyboard Return (ENTER)
104
105
  :"\n" => 40,
106
+ cr: 40,
105
107
  esc: 41, # Keyboard ESCAPE
106
108
  backspace: 42, # Keyboard DELETE (Backspace)
107
109
  tab: 43, # Keyboard Tab
@@ -297,7 +299,8 @@ KEYS = {
297
299
  left_arrow: :kp4,
298
300
  right_arrow: :kp6,
299
301
  up_arrow: :kp8,
300
- page_up: :kp9
302
+ page_up: :kp9,
303
+ windows_key: 0
301
304
  }
302
305
 
303
306
  class HidG0
@@ -310,7 +313,7 @@ class HidG0
310
313
 
311
314
  def keypress(key, duration: 0)
312
315
 
313
- keydown(key); sleep(duration); release_keys()
316
+ keydown(key.strip); sleep(duration); release_keys()
314
317
 
315
318
  end
316
319
 
@@ -319,10 +322,12 @@ class HidG0
319
322
  # current keymapping is for en-gb
320
323
 
321
324
  # £ is "\u{00A3}" in unicode
322
- [["\n",'{enter}'],["\u{00A3}","{shift+3}"],['"','{shift+2}']]\
325
+ [["\u{00A3}","{shift+3}"],['"','{shift+2}']]\
323
326
  .map {|x,y| s.gsub!(x,y) }
324
327
 
325
- s.scan(/\{[^\}]+\}|./).each do |x|
328
+ s.gsub(/\s*(?=\{)|(?<=\})\s*/,'').scan(/\{[^\}]+\}|./).each do |x|
329
+
330
+ puts ('x: ' + x.inspect).debug if @debug
326
331
 
327
332
  if x.length == 1 and x[0] != '{' then
328
333
 
@@ -330,28 +335,46 @@ class HidG0
330
335
 
331
336
  else
332
337
 
333
- keys = x[1..-2].split('+')
334
- puts ('keys: ' +keys.inspect).debug if @debug
338
+ # split by semicolon
339
+
340
+ x[1..-2].split(/\s*;\s*/).each do |instruction|
335
341
 
336
- if keys.length > 1 then
342
+ keys = instruction.split('+')
343
+
344
+
345
+ puts ('keys: ' + keys.inspect).debug if @debug
337
346
 
338
- # e.g. keys #=> ['ctrl', 's']
339
-
340
- key = KEYS[keys.pop.to_sym]
341
- modifier = keys.map {|x| MODIFIERS[x.to_sym]}.inject(:+)
347
+ if keys.length > 1 then
348
+
349
+ # e.g. keys #=> ['ctrl', 's']
342
350
 
343
- if @debug then
344
- puts ('key: ' + key.inspect).debug
345
- puts ('modifier: ' + modifier.inspect).debug
351
+ key = KEYS[keys.pop.to_sym]
352
+ modifier = keys.map {|x| MODIFIERS[x.to_sym]}.inject(:+)
353
+
354
+ if @debug then
355
+ puts ('key: ' + key.inspect).debug
356
+ puts ('modifier: ' + modifier.inspect).debug
357
+ end
358
+
359
+ write_report(modifier.chr + NULL_CHAR + key.chr + NULL_CHAR*5)
360
+ release_keys()
361
+
362
+ else
363
+
364
+ key = keys.first
365
+
366
+ if key =~ /sleep/ then
367
+
368
+ seconds = key[/(?<=sleep )\d+(?:\.\d+)/]
369
+ puts ('sleeping for ' + seconds + 'seconds').info if @debug
370
+ sleep seconds.to_f
371
+
372
+ else
373
+
374
+ keypress key, duration: @duration
375
+ end
346
376
  end
347
-
348
- write_report(modifier.chr + NULL_CHAR + key.chr + NULL_CHAR*5)
349
- release_keys()
350
-
351
- else
352
- keypress keys.first, duration: @duration
353
377
  end
354
-
355
378
  end
356
379
  end
357
380
 
@@ -363,6 +386,8 @@ class HidG0
363
386
 
364
387
  puts 'keydown | key: ' + key.inspect if @debug
365
388
 
389
+ return write_report(8.chr + NULL_CHAR*7) if key.to_s =~ /^windows_key$/
390
+
366
391
  if KEYS[key.to_sym].is_a? Integer then
367
392
 
368
393
  write_report(NULL_CHAR*2 + KEYS[key.to_sym].chr + NULL_CHAR*5)
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hidg0
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  PwTg5+TqjQvWRfpf4tDWra3/fS6sXSuA4aoh28J3YpuAS2upGYuCk61X4iEDYerh
36
36
  INwakAqcXQ4/4DC0SoRunSvJ
37
37
  -----END CERTIFICATE-----
38
- date: 2019-03-20 00:00:00.000000000 Z
38
+ date: 2019-03-30 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: c32
metadata.gz.sig CHANGED
Binary file