Class: XDo::Mouse
- Inherits:
-
Object
- Object
- XDo::Mouse
- Defined in:
- lib/x_do/mouse.rb
Overview
The mouse state for a libxdo context.
Instance Attribute Summary collapse
-
#xdo ⇒ Object
The XDo context that produced the window.
Instance Method Summary collapse
-
#click(button) ⇒ Object
Clicks a mouse button.
-
#initialize(xdo) ⇒ Mouse
constructor
Creates a mouse state wrapper for an XDo context.
-
#location ⇒ Object
- x, y, screen
-
array of mouse coordinates.
-
#move(x, y, screen) ⇒ Object
Moves the mouse to a new position.
-
#move_async(x, y, screen) ⇒ Object
Queues a mouse move request to the X server.
-
#move_relative(dx, dy) ⇒ Object
Moves the mouse relatively to its current position.
-
#move_relative_async(dx, dy) ⇒ Object
Queues a mouse move request to the X server.
-
#press(button) ⇒ Object
Presses a mouse button.
-
#release(button) ⇒ Object
Releases a mouse button.
-
#wait_for_move_from(x, y) ⇒ Object
Blocks until the mouse moves away from a position on screen.
-
#wait_for_move_to(x, y) ⇒ Object
Blocks until the mouse moves to a position on screen.
Constructor Details
#initialize(xdo) ⇒ Mouse
Creates a mouse state wrapper for an XDo context.
This constructor is called internally by XDo#mouse and client code should not need to call it directly.
Args:
xdo:: the XDo wrapping a libxdo context
13 14 15 16 |
# File 'lib/x_do/mouse.rb', line 13 def initialize(xdo) @xdo = xdo @_xdo_pointer = xdo._pointer end |
Instance Attribute Details
#xdo ⇒ Object
The XDo context that produced the window.
19 20 21 |
# File 'lib/x_do/mouse.rb', line 19 def xdo @xdo end |
Instance Method Details
#click(button) ⇒ Object
Clicks a mouse button.
70 71 72 |
# File 'lib/x_do/mouse.rb', line 70 def click() XDo::FFILib.xdo_click @_xdo_pointer, 0, end |
#location ⇒ Object
- x, y, screen
-
array of mouse coordinates.
22 23 24 25 26 27 28 29 |
# File 'lib/x_do/mouse.rb', line 22 def location x_pointer = FFI::MemoryPointer.new :int, 1 y_pointer = FFI::MemoryPointer.new :int, 1 screen_pointer = FFI::MemoryPointer.new :int, 1 XDo::FFILib.xdo_mouselocation @_xdo_pointer, x_pointer, y_pointer, screen_pointer [x_pointer.read_int, y_pointer.read_int, screen_pointer.read_int] end |
#move(x, y, screen) ⇒ Object
Moves the mouse to a new position.
32 33 34 35 36 37 38 |
# File 'lib/x_do/mouse.rb', line 32 def move(x, y, screen) old_location = self.location move_async x, y, screen unless old_location[0, 2] == [x, y] wait_for_move_from old_location[0], old_location[1] end end |
#move_async(x, y, screen) ⇒ Object
Queues a mouse move request to the X server.
41 42 43 |
# File 'lib/x_do/mouse.rb', line 41 def move_async(x, y, screen) XDo::FFILib.xdo_mousemove @_xdo_pointer, x, y, screen end |
#move_relative(dx, dy) ⇒ Object
Moves the mouse relatively to its current position.
46 47 48 49 50 51 52 |
# File 'lib/x_do/mouse.rb', line 46 def move_relative(dx, dy) old_location = self.location move_relative_async dx, dy unless dx == 0 && dy == 0 wait_for_move_from old_location[0], old_location[1] end end |
#move_relative_async(dx, dy) ⇒ Object
Queues a mouse move request to the X server.
55 56 57 |
# File 'lib/x_do/mouse.rb', line 55 def move_relative_async(dx, dy) XDo::FFILib.xdo_mousemove_relative @_xdo_pointer, dx, dy end |
#press(button) ⇒ Object
Presses a mouse button.
75 76 77 |
# File 'lib/x_do/mouse.rb', line 75 def press() XDo::FFILib.xdo_mousedown @_xdo_pointer, 0, end |
#release(button) ⇒ Object
Releases a mouse button.
80 81 82 |
# File 'lib/x_do/mouse.rb', line 80 def release() XDo::FFILib.xdo_mouseup @_xdo_pointer, 0, end |