-
Notifications
You must be signed in to change notification settings - Fork 11
/
mouse-click.cr
51 lines (51 loc) · 1.68 KB
/
mouse-click.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# MouseClick, WhichButton [, X, Y, ClickCount, Speed, D|U, R]
class Cmd::X11::Mouse::MouseClick < Cmd::Base
def self.min_args; 1 end
def self.max_args; 7 end
def run(thread, args)
parse_run(thread, args)
end
protected def parse_run(thread, args)
button = case args[0].downcase
when "right", "r" then XDo::Button::Right
when "middle", "m" then XDo::Button::Middle
when "wheelup", "wu" then XDo::Button::ScrollUp
when "wheeldown", "wd" then XDo::Button::ScrollDown
when "wheelleft", "wl" then XDo::Button::ScrollLeft
when "wheelright", "wr" then XDo::Button::ScrollRight
when "xbutton1", "x1" then XDo::Button::Button8
when "xbutton2", "x2" then XDo::Button::Button9
else XDo::Button::Left
end
current_x, current_y, screen = thread.runner.display.x_do.mouse_location
x = args[1]?.try &.to_i?
y = args[2]?.try &.to_i?
if x && y
if thread.settings.coord_mode_mouse == ::Run::CoordMode::RELATIVE
x, y = Cmd::X11::Window::Util.coord_relative_to_screen(thread, x, y)
end
end
count = args[3]?.try &.to_i? || 1
up = down = false
case args[5]?.try &.downcase
when "d" then down = true
when "u" then up = true
end
relative = args[6]?.try &.downcase == "r"
thread.runner.display.pause do
if x && y
if relative
thread.runner.display.x_do.move_mouse x, y
else
thread.runner.display.x_do.move_mouse x, y, screen
end
sleep thread.settings.mouse_delay.milliseconds if thread.settings.mouse_delay > -1
end
count.times do
thread.runner.display.x_do.mouse_down button if ! up
thread.runner.display.x_do.mouse_up button if ! down
sleep thread.settings.mouse_delay.milliseconds if thread.settings.mouse_delay > -1
end
end
end
end