diff --git a/docs/index.html b/docs/index.html index f0aed63..c3c3cbd 100644 --- a/docs/index.html +++ b/docs/index.html @@ -509,7 +509,7 @@

Table of contents

SetDefaultMouseSpeed
  • - SetMouseDelay + SetMouseDelay
  • @@ -1724,7 +1724,7 @@

    A_MouseDelay - # The current delay set by SetMouseDelay (always decimal, not hex). + # The current delay set by SetMouseDelay (always decimal, not hex). A_DefaultMouseSpeed @@ -2546,7 +2546,7 @@

    The "Last Found" Window

    Sets the delay that will occur after each keystroke sent by Send or ControlSend. - SetMouseDelay + SetMouseDelay Sets the delay that will occur after each mouse movement or click. @@ -10809,7 +10809,7 @@

    Examples

    SetDefaultMouseSpeed, 0 ; Move the mouse instantly like AutoIt2.

    -
    +
    #

    SetMouseDelay


    @@ -10834,7 +10834,7 @@

    Examples

     

    Remarks

    A short delay (sleep) is automatically and invisibly done after every mouse movement or click generated by MouseMove, MouseClick, and MouseClickDrag. This is done to improve the reliability of scripts because a window sometimes can't keep up with a rapid flood of mouse events.

    -

    Due to the granularity of the OS's time-keeping system, delays might be rounded up to the nearest multiple of 10. For example, a delay between 1 and 10 (inclusive) is equivalent to 10 on Windows XP (and probably NT & 2k).

    +

    Due to the granularity of the OS's time-keeping system, delays might be rounded up to the nearest multiple of 10. For example, a delay between 1 and 10 (inclusive) is equivalent to 10 on Windows XP (and probably NT & 2k).

    A delay of 0 internally executes a Sleep(0), which yields the remainder of the script's timeslice to any other process that may need it. If there is none, Sleep(0) will not sleep at all. By contrast, a delay of -1 will never sleep.

    If unset, the default delay is 10.

    The built-in variable A_MouseDelay contains the current setting.

    diff --git a/src/cmd/x11/mouse/mouse-click.cr b/src/cmd/x11/mouse/mouse-click.cr index 701a42b..70206c1 100644 --- a/src/cmd/x11/mouse/mouse-click.cr +++ b/src/cmd/x11/mouse/mouse-click.cr @@ -24,9 +24,6 @@ class Cmd::X11::Mouse::MouseClick < Cmd::Base if thread.settings.coord_mode_mouse == ::Run::CoordMode::RELATIVE x, y = Cmd::X11::Window::Util.coord_relative_to_screen(thread, x, y) end - else - x = current_x - y = current_y end count = args[3]?.try &.to_i? || 1 up = down = false @@ -36,14 +33,18 @@ class Cmd::X11::Mouse::MouseClick < Cmd::Base end relative = args[6]?.try &.downcase == "r" thread.runner.display.pause do - if relative - thread.runner.display.x_do.move_mouse x, y - else - thread.runner.display.x_do.move_mouse x, y, screen + 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 diff --git a/src/cmd/x11/mouse/mouse-move.cr b/src/cmd/x11/mouse/mouse-move.cr index 673c9be..4c5e153 100644 --- a/src/cmd/x11/mouse/mouse-move.cr +++ b/src/cmd/x11/mouse/mouse-move.cr @@ -17,5 +17,6 @@ class Cmd::X11::Mouse::MouseMove < Cmd::Base thread.runner.display.x_do.move_mouse x, y, screen end end + sleep thread.settings.mouse_delay.milliseconds if thread.settings.mouse_delay > -1 end end \ No newline at end of file diff --git a/src/cmd/x11/mouse/set-mouse-delay.cr b/src/cmd/x11/mouse/set-mouse-delay.cr new file mode 100644 index 0000000..84ef35e --- /dev/null +++ b/src/cmd/x11/mouse/set-mouse-delay.cr @@ -0,0 +1,8 @@ +# SetMouseDelay, Delay +class Cmd::X11::Mouse::SetMouseDelay < Cmd::Base + def self.min_args; 1 end + def self.max_args; 1 end + def run(thread, args) + thread.settings.mouse_delay = args[0].to_i if args[0].to_i? + end +end \ No newline at end of file diff --git a/src/run/thread.cr b/src/run/thread.cr index 6d58fce..594c4e7 100644 --- a/src/run/thread.cr +++ b/src/run/thread.cr @@ -21,6 +21,7 @@ module Run property detect_hidden_windows = false property key_delay = 10 property key_press_duration = -1 + property mouse_delay = 10 property ahk_x11_track_performance = false end @@ -230,6 +231,8 @@ module Run @settings.detect_hidden_windows ? "On" : "Off" when "a_keydelay" @settings.key_delay.to_s + when "a_mousedelay" + @settings.mouse_delay.to_s when "a_linenumber" (@stack.last.line_no + 1).to_s when "a_thislabel" diff --git a/tests.ahk b/tests.ahk index bb94d2d..dbade7f 100755 --- a/tests.ahk +++ b/tests.ahk @@ -6,6 +6,7 @@ N_TESTS = 70 SetKeyDelay, 0 +SetMouseDelay, 0 GoSub, run_tests if tests_run != %N_TESTS%