class HidG0Plus

Public Class Methods

new(instructions='', dev: '/dev/hidg0', debug: false, progress_units: 100, chunk: true) click to toggle source
Calls superclass method HidG0::new
# File lib/hidg0.rb, line 436
def initialize(instructions='', dev: '/dev/hidg0', debug: false, 
               progress_units: 100, chunk: true)
  
  humanspeed = chunk == true
  super(dev, debug: debug, humanspeed: humanspeed)
  @index, @progress_units = 0, progress_units
  
  a = parse_keys(instructions).map do |x|
    
    puts 'x: ' + x.inspect if @debug
    
    if x[0] == '{' then

      x[1..-2].strip.split(/[;,]/).map do |item|
        
        if item.strip  =~ /^sleep /
        
          next
          
        elsif item =~ /\w+\s*\*\s*\d+/
          
          key, n = item.split(/\*/,2)
          [key] * n.to_i
          
        else
          "{%s}" % item.strip
        end
        
      end.compact
      
    else
      x
    end
    
  end.flatten
  
  @keys = chunk ? a.chunk_while {|x| x.length == 1}.map(&:join) : a
  
end

Public Instance Methods

index() click to toggle source
# File lib/hidg0.rb, line 476
def index()
  @index
end
keys() click to toggle source
# File lib/hidg0.rb, line 480
def keys()    
  @keys    
end
next_key() click to toggle source
# File lib/hidg0.rb, line 484
def next_key()
  @keys[@index]
end
prev_key() click to toggle source
# File lib/hidg0.rb, line 488
def prev_key()
  @keys[@index-1] unless @index == 0
end
progress(units=@progress_units) click to toggle source
# File lib/hidg0.rb, line 492
def progress(units=@progress_units)
  (units / (@keys.length / @index.to_f)).round
end
reset() click to toggle source
# File lib/hidg0.rb, line 496
def reset()
  @index = 0
end
sendkey() click to toggle source
# File lib/hidg0.rb, line 500
def sendkey()
  
  return if @index >= @keys.length
  key = @keys[@index]
  key.length > 1 ? sendkeys(key) : keypress(key) 
  @index+=1
  progress()
  
end