Skip to content

Commit

Permalink
fix daemon mouse mode
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Aug 21, 2021
1 parent 689df64 commit c0947cd
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
15 changes: 12 additions & 3 deletions ahk/templates/_daemon.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ MouseMove(ByRef command) {

CoordMode(ByRef command) {
if (command.Length() = 2) {
CoordMode, command[2]
CoordMode,% command[2]
} else {
CoordMode, command[2], command[3]
CoordMode,% command[2],% command[3]
}
}

Expand Down Expand Up @@ -148,7 +148,7 @@ KeyWait(ByRef command) {
}

SetKeyDelay(ByRef command) {
SetKeyDelay, command[2]
SetKeyDelay, command[2], command[3]
}

Join(sep, params*) {
Expand Down Expand Up @@ -374,6 +374,15 @@ WindowList(ByRef command) {
}

WinSend(ByRef command) {
title := command[2]
command.RemoveAt(1)
command.RemoveAt(1)
str := Join(",", command*)
keys := Unescape(str)
ControlSend,,% keys, %title%
}

WinSendRaw(ByRef command) {
title := command[2]
command.RemoveAt(1)
command.RemoveAt(1)
Expand Down
15 changes: 12 additions & 3 deletions ahk/templates/daemon.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ MouseMove(ByRef command) {

CoordMode(ByRef command) {
if (command.Length() = 2) {
CoordMode, command[2]
CoordMode,% command[2]
} else {
CoordMode, command[2], command[3]
CoordMode,% command[2],% command[3]
}
}

Expand Down Expand Up @@ -156,7 +156,7 @@ KeyWait(ByRef command) {
}

SetKeyDelay(ByRef command) {
SetKeyDelay, command[2]
SetKeyDelay, command[2], command[3]
}

Join(sep, params*) {
Expand Down Expand Up @@ -382,6 +382,15 @@ WindowList(ByRef command) {
}

WinSend(ByRef command) {
title := command[2]
command.RemoveAt(1)
command.RemoveAt(1)
str := Join(",", command*)
keys := Unescape(str)
ControlSend,,% keys, %title%
}

WinSendRaw(ByRef command) {
title := command[2]
command.RemoveAt(1)
command.RemoveAt(1)
Expand Down
2 changes: 2 additions & 0 deletions ahk/templates/daemon/mouse_position.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CoordMode,Mouse,{{mode}}
MouseGetPos, xpos, ypos
2 changes: 1 addition & 1 deletion ahk/templates/mouse/mouse_drag.ahk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base.ahk" %}
{% block body %}
CoordMode, Mouse, {{mode}}
CoordMode,Mouse,{{mode}}
MouseClickDrag,{{button}},{{x1}},{{y1}},{{x2}},{{y2}}{% if speed %},{{speed}}{% endif %}{% if relative %},R{% endif %}
{% endblock body %}
4 changes: 2 additions & 2 deletions ahk/templates/mouse/mouse_move.ahk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "base.ahk" %}
{% block body %}
CoordMode, Mouse, {{mode}}
MouseMove, {{x}}, {{y}}, {{speed}}{% if relative %}, R{% endif %}
CoordMode,Mouse,{{mode}}
MouseMove,{{x}},{{y}},{{speed}}{% if relative %},R{% endif %}
{% endblock body %}
2 changes: 1 addition & 1 deletion ahk/templates/mouse/mouse_position.ahk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "base.ahk" %}
{% block body %}
CoordMode, Mouse, {{mode}}
CoordMode,Mouse,{{mode}}
MouseGetPos, xpos, ypos
s .= Format("({}, {})", xpos, ypos)
FileAppend, %s%, *
Expand Down
15 changes: 15 additions & 0 deletions tests/unittests/test_mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
)
sys.path.insert(0, project_root)
from ahk import AsyncAHK, AHK
from ahk.daemon import AHKDaemon



Expand Down Expand Up @@ -47,17 +48,31 @@ def test_mouse_move_callable_speed(self):

def test_mouse_drag(self):
self.notepad_process = subprocess.Popen('notepad')
time.sleep(0.5)
notepad = self.ahk.find_window(title=b"Untitled - Notepad")
win_width = notepad.width
win_height = notepad.height
print(*notepad.position)
self.ahk.mouse_move(*notepad.position)
time.sleep(1)
# moving the mouse to the window position puts it in a position where it can be resized by dragging ↖ ↘
# after this, we expect the window height/width to shrink by 10px
self.ahk.mouse_drag(10, 10, relative=True)
assert notepad.width == win_width - 10
assert notepad.height == win_height - 10


class TestMouseDaemon(TestMouse):
def setUp(self) -> None:
self.ahk = AHKDaemon()
self.ahk.start()
self.original_position = self.ahk.mouse_position
self.notepad_process = None

def tearDown(self) -> None:
super().tearDown()
self.ahk.stop()

class TestMouseAsync(IsolatedAsyncioTestCase):
def setUp(self) -> None:
self.ahk = AsyncAHK()
Expand Down

0 comments on commit c0947cd

Please sign in to comment.