hidg0 0.3.0 → 0.4.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: ed5e0205a0076670f8d7daa2a0b3d2f435c201b39182761380863f1bc81a4751
4
- data.tar.gz: d035c0286f3214cdf202245b2581e0de020079564b12ab0356dbee00a99896d4
3
+ metadata.gz: 18bb1d1ce3cc1772d08c9174f3b74fa72854063298be6ff49179dfea00f60dc5
4
+ data.tar.gz: 44c366862cf4516459158d628b1ef2e7fc4e68fa48ca37dfec2cc60b0f9abfa8
5
5
  SHA512:
6
- metadata.gz: a0b5ebbfbedfbf3ef8b3a1d036afa193ce715de54b0f1362e06dd6bf4a20305470a340e15e0cff59968bc50ce0c0e722600c1766c7ae62667208fe5e9abce7ec
7
- data.tar.gz: 10ee00392668a9d176ffab716894b5522a4ddb8fad5e2f42d956716743ceb7d7f89336d87b0cf5c35c47e8bd5f282dc5505885e37b6e9ab73b8fc53b541a1c7a
6
+ metadata.gz: 459c736b804d8b8c061fb85a8d5bb322c5dd6b246890dc7f9caf535d2dccfc15ffc2fc375e543e5baf72161b042747760065e0e589ed0caf6108547621781fd6
7
+ data.tar.gz: c104f3d0ec5e172a9c7c996f2e65e83b236cd840d1ed26105457bc70e9f62d27f7baf19ca9e7e04c6526fa34f2102a466601b0dd71d0adc32fa3cb7efeac242d
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/hidg0.rb CHANGED
@@ -311,9 +311,10 @@ class HidG0
311
311
  @duration = humanspeed ? 0.3 : 0
312
312
  end
313
313
 
314
- def keypress(key, duration: 0)
314
+ def keypress(raw_key, duration: 0)
315
315
 
316
- keydown(key.strip); sleep(duration); release_keys()
316
+ key = raw_key.strip.empty? ? raw_key : raw_key.strip
317
+ keydown(key); sleep(duration); release_keys()
317
318
 
318
319
  end
319
320
 
@@ -322,10 +323,7 @@ class HidG0
322
323
  # current keymapping is for en-gb
323
324
 
324
325
  # £ is "\u{00A3}" in unicode
325
- [["\u{00A3}","{shift+3}"],['"','{shift+2}']]\
326
- .map {|x,y| s.gsub!(x,y) }
327
-
328
- s.gsub(/\s*(?=\{)|(?<=\})\s*/,'').scan(/\{[^\}]+\}|./).each do |x|
326
+ parse_keys(s).each do |x|
329
327
 
330
328
  puts ('x: ' + x.inspect).debug if @debug
331
329
 
@@ -339,6 +337,12 @@ class HidG0
339
337
 
340
338
  x[1..-2].split(/\s*;\s*/).each do |instruction|
341
339
 
340
+ if instruction =~ /\*\s*\d+/ then
341
+ key, n = instruction.split('*',2)
342
+ n.to_i.times {keypress(key, duration: @duration) }
343
+ next
344
+ end
345
+
342
346
  keys = instruction.split('+')
343
347
 
344
348
 
@@ -379,6 +383,19 @@ class HidG0
379
383
  end
380
384
 
381
385
  end
386
+
387
+ protected
388
+
389
+ def parse_keys(raw_s)
390
+
391
+ s = raw_s.clone
392
+
393
+ [["\u{00A3}","{shift+3}"],['"','{shift+2}']]\
394
+ .map {|x,y| s.gsub!(x,y) }
395
+
396
+ s.gsub(/\s*(?=\{)|(?<=\})\s*/,'').scan(/\{[^\}]+\}|./)
397
+
398
+ end
382
399
 
383
400
  private
384
401
 
@@ -412,3 +429,68 @@ class HidG0
412
429
  end
413
430
  end
414
431
 
432
+ class HidG0Plus < HidG0
433
+
434
+ def initialize(instructions='', dev: '/dev/hidg0', debug: false)
435
+
436
+ super(dev, debug: debug, humanspeed: false)
437
+ @index= 0
438
+
439
+ @keys = parse_keys(instructions).map do |x|
440
+
441
+ puts 'x: ' + x.inspect if @debug
442
+
443
+ if x[0] == '{' then
444
+
445
+ x[1..-2].strip.split(/[;,]/).map do |item|
446
+
447
+ if item.strip =~ /^sleep /
448
+
449
+ next
450
+
451
+ elsif item =~ /\w+\s*\*\s*\d+/
452
+
453
+ key, n = item.split(/\*/,2)
454
+ [key] * n.to_i
455
+
456
+ else
457
+ "{%s}" % item.strip
458
+ end
459
+
460
+ end.compact
461
+
462
+ else
463
+ x
464
+ end
465
+
466
+ end.flatten
467
+
468
+ end
469
+
470
+ def index()
471
+ @index
472
+ end
473
+
474
+ def keys()
475
+
476
+ @keys
477
+
478
+ end
479
+
480
+ def sendkey()
481
+
482
+ key = @keys[@index]
483
+ key[0] == '{' ? sendkeys(key) : keypress(key)
484
+ @index+=1
485
+
486
+ end
487
+
488
+ def next_key()
489
+ @keys[@index]
490
+ end
491
+
492
+ def prev_key()
493
+ @keys[@index-1] unless @index == 0
494
+ end
495
+
496
+ end
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file