class Xdrp::Recorder
Attributes
xml[R]
Public Class Methods
new(levelx=KEYBOARD_MOUSE, level: levelx, debug: false)
click to toggle source
level:
1 = mouse 2 = keyboard 3 = keyboard + mouse
# File lib/xdrp.rb, line 31 def initialize(levelx=KEYBOARD_MOUSE, level: levelx, debug: false) @xiw = XInputWrapper.new(verbose: true, debug: debug, callback: self) @mouse, @keyboard = false, false case level when 1 @mouse = true when 2 @keyboard = true when 3 @mouse, @keyboard = true, true end end
Public Instance Methods
on_keypress(key, keycode, modifier=nil)
click to toggle source
# File lib/xdrp.rb, line 47 def on_keypress(key, keycode, modifier=nil) if @debug then puts 'key: ' + key.inspect puts 'keycode: ' + keycode.inspect puts 'modifier: ' + modifier.inspect end stop() if modifier and modifier[0] == :alt and key == :z return unless @keyboard add_sleep() if Time.now > (@t1 + 2) if @a.length >= 1 and @a[-1][0] == :type then if modifier.nil? or (modifier and modifier.empty?) then @a[-1][2] += key.to_s.sub('{space}', ' ') else if modifier.length < 2 then if modifier.first == :shift and (keycode.between?(10,21) \ or keycode.between?(24,35) \ or keycode.between?(38,48)) then char = if key.to_s =~ /[a-z]/ then key.to_s.upcase elsif key.to_s =~ /[0-9]/ %w[) ! " £ $ % ^ & * ( ][key.to_s.to_i] else lsym = %w(` - = [ ] ; ' # \ , . /) if lsym.include? key.to_s then usym = %w(¬ _ + { } : @ ~ | < > ?) lsym.zip(usym).to_h[key.to_s] end end @a[-1][2] += char else @a << [modifier.first, {key: key}] end end end else a = case key.to_s[/^\{(\w+)\}$/,1] when 'enter' [:enter] when 'tab' [:tab] else [:type, {}, key.to_s.sub(/\{space\}/, ' ')] end @a << a end end
on_mouse_scrolldown()
click to toggle source
# File lib/xdrp.rb, line 143 def on_mouse_scrolldown() return unless @mouse puts 'mouse is scrolling down' if @debug add_sleep() if Time.now > (@t1 + 2) @a << [:mousewheel, {scroll: 'down'}] end
on_mouse_scrollup()
click to toggle source
# File lib/xdrp.rb, line 153 def on_mouse_scrollup() return unless @mouse puts 'mouse is scrolling up ' if @debug add_sleep() if Time.now > (@t1 + 2) @a << [:mousewheel, {scroll: 'up'}] end
on_mousedown(button, x, y)
click to toggle source
# File lib/xdrp.rb, line 116 def on_mousedown(button, x, y) return unless @mouse puts "mouse %s button down at %s, %s" % [button, x, y] if @debug add_sleep() if Time.now > (@t1 + 2) @a << [:mouse, {click: button, x: x, y: y}] end
on_mousemove(x, y)
click to toggle source
# File lib/xdrp.rb, line 133 def on_mousemove(x, y) return unless @mouse puts 'mouse is moving at ' + x.to_s + ' y ' + y.to_s if @debug add_sleep() if Time.now > (@t1 + 2) @a << [:mousemove, {x: x, y: y}] end
on_mouseup(button, x, y)
click to toggle source
# File lib/xdrp.rb, line 126 def on_mouseup(button, x, y) return unless @mouse puts "mouse %s button up at %s, %s" % [button, x, y] if @debug end
save(filepath)
click to toggle source
# File lib/xdrp.rb, line 163 def save(filepath) File.write filepath, xml() end
start()
click to toggle source
# File lib/xdrp.rb, line 167 def start() @a = [] Thread.new { @xiw.listen } puts 'recording ...' @t1 = Time.now end
stop()
click to toggle source
# File lib/xdrp.rb, line 176 def stop() @xiw.stop = true @doc = Rexle.new(['xdrp', {}, '', *@a]) puts 'recording stopped' end
Private Instance Methods
add_sleep()
click to toggle source
# File lib/xdrp.rb, line 190 def add_sleep() @a << [:sleep, {duration: (Time.now - @t1).round}] @t1 = Time.now end