Class: Samscript::Mouse

Inherits:
Object
  • Object
show all
Defined in:
lib/samscript/mouse.rb

Class Method Summary collapse

Class Method Details

.click(button = :left) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/samscript/mouse.rb', line 34

def self.click button = :left
  masks = { left:  InputEvent::BUTTON1_MASK,
            right: InputEvent::BUTTON2_MASK }
  mask = masks[button]

  robot.mouse_press mask
  robot.mouse_release mask
end

.position(params = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/samscript/mouse.rb', line 14

def self.position params = {}
  as = params[:as] || :point
  point = MouseInfo.get_pointer_info.get_location
  vector = Vector[point.get_x, point.get_y]

  case as
  when :point
    return point
  when :vector
    return vector
  end
end

.position=(point) ⇒ Object



27
28
29
30
31
32
# File 'lib/samscript/mouse.rb', line 27

def self.position= point
  x, y = point[0], point[1] if point.is_a? Vector
  x, y = point.get_x, point.get_y if point.is_a? Point

  robot.mouse_move(x, y)
end

.robotObject



10
11
12
# File 'lib/samscript/mouse.rb', line 10

def self.robot
  @robot ||= Robot.new
end