Module: XDo::Simulatable

Defined in:
lib/xdo/simulatable.rb

Overview

Mixin that allows String-like objects to be directly simulated. You can use it with Ruby’s String class:

require "xdo/simulatable"

class String
  include XDo::Simulatable
  def to_xdo
    to_s
  end
end

"abc".simulate

Every method in this module calls ##to_xdo on self first, so make sure this method returns a xdo-usable String (i.e. no invisible characters except newline, tab and space).

Instance Method Summary collapse

Instance Method Details

#down(w_id = nil) ⇒ Object

Holds the first key of self down.



39
40
41
# File 'lib/xdo/simulatable.rb', line 39

def down(w_id = nil)
  XDo::Keyboard.key_down(to_xdo[0], w_id)
end

#simulate(raw = false, w_id = nil) ⇒ Object

Simulates self as keystrokes. Escape sequences are allowed.



29
30
31
# File 'lib/xdo/simulatable.rb', line 29

def simulate(raw = false, w_id = nil)
  XDo::Keyboard.simulate(to_xdo, raw, w_id)
end

#type(w_id = nil) ⇒ Object

Types self as keystrokes. Ignores escape sequences.



34
35
36
# File 'lib/xdo/simulatable.rb', line 34

def type(w_id = nil)
  XDo::Keyboard.type(to_xdo, w_id)
end

#up(w_id = nil) ⇒ Object

Releases the first key of self if it’s hold down by #down.



45
46
47
# File 'lib/xdo/simulatable.rb', line 45

def up(w_id = nil)
  XDo::Keyboard.key_up(to_xdo[0], w_id)
end