Class: FingerPoken::Target::Xdo

Inherits:
FingerPoken::Target
  • Object
show all
Defined in:
lib/fingerpoken/xdo.rb

Defined Under Namespace

Modules: LibXdo Classes: XdoSearch

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Xdo

class XdoSearch



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fingerpoken/xdo.rb', line 38

def initialize(config)
  super(config)
  @xdo = LibXdo::xdo_new(nil)
  if @xdo.null?
     raise "xdo_new failed"
  end

  search = XdoSearch.new
  search[:searchmask] = 1 << 2 # SEARCH_NAME, from xdo.h
  search[:max_depth] = 0
  search[:winname] = FFI::MemoryPointer.new(:char, 3)
  search[:winname].put_string(0, ".*")
  ptr_nwindows = FFI::MemoryPointer.new(:ulong, 1)
  ptr_winlist = FFI::MemoryPointer.new(:pointer, 1)
  LibXdo::xdo_window_search(@xdo, search, ptr_winlist, ptr_nwindows)
  nwindows = ptr_nwindows.read_long
  @rootwin = ptr_winlist.read_pointer.read_array_of_long(nwindows)[0]

  ptr_x = FFI::MemoryPointer.new(:int, 1)
  ptr_y = FFI::MemoryPointer.new(:int, 1)

  LibXdo::xdo_get_window_size(@xdo, @rootwin, ptr_x, ptr_y)
  @screen_x = ptr_x.read_int
  @screen_y = ptr_y.read_int
end

Instance Method Details

#click(button) ⇒ Object



78
79
80
# File 'lib/fingerpoken/xdo.rb', line 78

def click(button)
  return LibXdo::xdo_click(@xdo, 0, button.to_i)
end

#keypress(key) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/fingerpoken/xdo.rb', line 94

def keypress(key)
  if key.is_a?(String)
    if key.length == 1
      # Assume letter
      LibXdo::xdo_type(@xdo, 0, key, 12000)
    else
      # Assume keysym
      LibXdo::xdo_keysequence(@xdo, 0, key, 12000)
    end
  else
    # type printables, key others.
    if 32.upto(127).include?(key)
      LibXdo::xdo_type(@xdo, 0, key.chr, 12000)
    else
      case key
        when 8 
          LibXdo::xdo_keysequence(@xdo, 0, "BackSpace", 12000)
        when 13
          LibXdo::xdo_keysequence(@xdo, 0, "Return", 12000)
        else
          puts "I don't know how to type web keycode '#{key}'"
        end # case key
    end # if 32.upto(127).include?(key)
  end # if key.is_a?String
  return nil
end

#mousedown(button) ⇒ Object



82
83
84
# File 'lib/fingerpoken/xdo.rb', line 82

def mousedown(button)
  return LibXdo::xdo_mousedown(@xdo, 0, button.to_i)
end

#mousemove_absolute(px, py) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/fingerpoken/xdo.rb', line 68

def mousemove_absolute(px, py)
  # Edges may be hard to hit on some devices, so inflate things a bit.
  xbuf = @screen_x * 0.1
  ybuf = @screen_y * 0.1
  x = (((@screen_x + xbuf) * px) - (xbuf / 2)).to_i
  y = (((@screen_y + ybuf) * py) - (ybuf / 2)).to_i

  return LibXdo::xdo_mousemove(@xdo, x, y, 0)
end

#mousemove_relative(x, y) ⇒ Object



64
65
66
# File 'lib/fingerpoken/xdo.rb', line 64

def mousemove_relative(x, y)
  return LibXdo::xdo_mousemove_relative(@xdo, x, y)
end

#mouseup(button) ⇒ Object



86
87
88
# File 'lib/fingerpoken/xdo.rb', line 86

def mouseup(button)
  return LibXdo::xdo_mouseup(@xdo, 0, button.to_i)
end

#type(string) ⇒ Object



90
91
92
# File 'lib/fingerpoken/xdo.rb', line 90

def type(string)
  return LibXdo::xdo_type(@xdo, 0, string, 12000)
end