class XDo
- XDo
- Reference
- Object
Overview
XDo is a Crystal interface for libxdo,
the C library that backs xdotool.
It exposes most of the functionality of xdotool, allowing
users to write Crystal programs that manage windows in an X11 instance.
The easiest way to use XDo is via XDo.act:
XDo.act do
active_window do |win|
win.type "hello from Crystal!"
end
end
Defined in:
x_do.crx_do/enums.cr
x_do/libxdo.cr
x_do/version.cr
Constant Summary
-
DEFAULT_DELAY =
12000 -
VERSION =
"0.8.3"
Constructors
-
.new(display = ENV["DISPLAY"]?)
Creates a new
XDoinstance with the given X11 display.
Class Method Summary
-
.act(&)
Yields a block with an
XDoinstance, providing a DSL for interaction. -
.lib_version
Returns the version of
libxdobeing used as aString. -
.symbol_map
Returns a
Hash(String, String)indicating the current symbol map.
Instance Method Summary
-
#active_modifiers
Returns a list of
XDo::LibXDo::Charcodemaps indicating all active modifier keys. -
#active_window(&)
Returns the
Windowthat is currently active. -
#active_window
Returns the
Windowthat is currently active. -
#clear_active_modifiers
TODO implement
-
#click(button : Button)
Click the given mouse button on the active window (mouse-down + mouse-up)
-
#click(button : Button, repeat, delay = DEFAULT_DELAY)
Click the given mouse button repeat times, with delay between each click.
-
#desktop
Returns the current desktop's number.
-
#desktop=(desktop)
Sets the current desktop.
-
#desktops
Returns the number of desktops.
-
#desktops=(ndesktops)
Sets the number of desktops.
-
#disable_feature(feature : XDoFeatures)
Disable an
xdofeature. - #display : String?
-
#enable_feature(feature : XDoFeatures)
Enable an
xdofeature. -
#finalize
Destroys the instance's internal state.
-
#focused_window(*, sane = true)
Returns the
Windowthat currently has focus. -
#focused_window(*, sane = true, &)
Returns the
Windowthat currently has focus. -
#has_feature?(feature : XDoFeatures)
Test whether a feature is enabled.
-
#input_state : KeyMask
Returns the input state, which is the
ORof any active modifiers in theKeyMask. -
#keys(keys : String, delay = DEFAULT_DELAY)
Send some keys (down + up) to the active window, with delay between them.
-
#keys_down(keys : String, delay = DEFAULT_DELAY)
Send some key press (down) events for the given keys, with delay between them.
-
#keys_raw(keys : Array(LibXDo::Charcodemap), *, pressed : Bool, modifier = 0, delay = DEFAULT_DELAY)
Send some key events by specifying keysyms and modifiers directly, with delay between them.
-
#keys_up(keys : String, delay = DEFAULT_DELAY)
Send some key release (up) events for the given keys, with delay between them.
-
#mouse_down(button : Button)
Send a mouse-down event for the given mouse button to the active window.
-
#mouse_location
Returns the mouse's current position as a tuple of
xandycoordinates, thescreenit's on, and theWindowit's over. -
#mouse_up(button : Button)
Send a mouse-up event for the given mouse button to the active window.
-
#mouse_window(&)
Returns the
Windowthat the mouse is currently over. -
#mouse_window
Returns the
Windowthat the mouse is currently over. -
#move_mouse(x, y, screen)
Moves the mouse to coordinates x, y on the given screen.
-
#move_mouse(x, y)
Moves the mouse to coordinates x, y relative to its current position.
- #on_mouse_move(&)
-
#on_mouse_move_from(x, y, &)
Wait for the mouse to move from the coordinates x, y.
-
#on_mouse_move_to(x, y, &)
Wait for the mouse to move to the coordinates x, y.
- #search(query)
-
#search(&)
Like
#search(query), but yields a block to build the query directly. -
#select_window(&)
Returns the
Windowselected interactively. -
#select_window
Returns the
Windowselected interactively. -
#set_active_modifiers
TODO implement
-
#type(text : String, delay = DEFAULT_DELAY)
Send some text to the active window, with delay between the keystrokes.
-
#viewport
Gets the desktop viewport as an
x,ytuple. -
#viewport=(tup)
Sets the desktop viewport (only relevant if
_NET_DESKTOP_VIEWPORTis supported). -
#viewport_dimensions(screen)
Gets the dimensions of the given screen's viewport as a
width,heighttuple. -
#wait_for_mouse_move_from(x, y)
Wait for the mouse to move from the coordinates x, y.
-
#wait_for_mouse_move_to(x, y)
Wait for the mouse to move to the coordinates x, y.
Constructor Detail
Creates a new XDo instance with the given X11 display.
# create an instance on the default display or `DISPLAY` env variable
xdo = XDo.new
# ...or with a different X display
xdo2 = XDo.new(":2")
# ... do some work ...
Class Method Detail
Yields a block with an XDo instance, providing a DSL for interaction.
XDo.act do
select_window do |win|
win.unmap!
sleep 1
win.map!
win.type "hello"
end
desktop = 3
end
Returns a Hash(String, String) indicating the current symbol map.
XDo.symbol_map # => {"alt" => "Alt_L", "ctrl" => "Control_L"}
Instance Method Detail
Returns a list of XDo::LibXDo::Charcodemaps indicating all active modifier keys.
Click the given mouse button on the active window (mouse-down + mouse-up)
Click the given mouse button repeat times, with delay between each click.
Returns the Window that currently has focus.
When sane is set to true, returns the first ancestor-or-self window
with the WM_CLASS property. When set to false, returns the actual focused
window (which may not be the application's top-level window).
Returns the Window that currently has focus.
When sane is set to true, returns the first ancestor-or-self window
with the WM_CLASS property. When set to false, returns the actual focused
window (which may not be the application's top-level window).
Returns the input state, which is the OR of any active modifiers
in the KeyMask.
Send some keys (down + up) to the active window, with delay between them.
keys "Ctrl+s"
Send some key press (down) events for the given keys, with delay between them.
See #keys_up.
keys_down "Ctrl+o"
Send some key events by specifying keysyms and modifiers directly,
with delay between them.
You most likely want to use #keys or #type instead, however this function
skips the string parsing and should consequently run slightly faster.
key1 = XDo::LibXDo::Charcodemap.new
key1.code = 38
key1.modmask = 1
key2 = XDo::LibXDo::Charcodemap.new
key2.code = 56
keys = [key1, key2]
# Sends `AB`
keys_raw keys, pressed: true
keys_raw keys, pressed: false
Send some key release (up) events for the given keys, with delay between them.
See #keys_down.
keys_up "Ctrl+o"
Send a mouse-down event for the given mouse button to the active window.
Returns the mouse's current position as a tuple of x and y coordinates,
the screen it's on, and the Window it's over.
x, y, screen, win = xdo.mouse_location
Send a mouse-up event for the given mouse button to the active window.
Takes a Search and runs it, returning a list of Windows matching the search.
XDo.act do
query = XDo::Search.build { window_name "Firefox" }
winds = search(query)
puts winds
end
Like #search(query), but yields a block to build the query directly.
XDo.act do
winds = search { window_name "Firefox" }
puts winds
end
Send some text to the active window, with delay between the keystrokes.
type "hello from Crystal!"
Sets the desktop viewport (only relevant if _NET_DESKTOP_VIEWPORT is supported).
XDo.act do
viewport = {x, y}
end
Gets the dimensions of the given screen's viewport as a width, height tuple.