Skip to content

Commit d75dcdc

Browse files
committed
set/get coord mode
1 parent 4cd6be4 commit d75dcdc

5 files changed

Lines changed: 90 additions & 58 deletions

File tree

ahk/_async/engine.py

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,16 @@ async def get_title_match_speed(self) -> str:
221221
resp = await self._transport.function_call('AHKGetTitleMatchSpeed')
222222
return resp
223223

224+
async def set_coord_mode(self, target: CoordModeTargets, relative_to: CoordModeRelativeTo = 'Screen') -> None:
225+
args = [str(target), str(relative_to)]
226+
await self._transport.function_call('AHKSetCoordMode', args)
227+
return None
228+
229+
async def get_coord_mode(self, target: CoordModeTargets) -> str:
230+
args = [str(target)]
231+
resp = await self._transport.function_call('AHKGetCoordMode', args)
232+
return resp
233+
224234
# fmt: off
225235
@overload
226236
async def control_click(self, *, button: Literal['L', 'R', 'M', 'LEFT', 'RIGHT', 'MIDDLE'] = 'L', click_count: int = 1, options: str = '', control: str = '', title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None) -> None: ...
@@ -762,34 +772,6 @@ async def key_wait(
762772
resp = await self._transport.function_call('AHKKeyWait', args)
763773
return resp
764774

765-
# async def mouse_position(self):
766-
# raise NotImplementedError()
767-
768-
async def mouse_wheel(
769-
self,
770-
direction: Union[
771-
Literal['up'], Literal['down'], Literal['UP'], Literal['DOWN'], Literal['Up'], Literal['Down']
772-
],
773-
*args: Any,
774-
**kwargs: Any,
775-
) -> None:
776-
raise NotImplementedError()
777-
778-
# async def reg_delete(self, key_name: str, value_name: str = '') -> None:
779-
# raise NotImplementedError()
780-
#
781-
# async def reg_loop(self, reg: str, key_name: str, mode=''):
782-
# raise NotImplementedError()
783-
#
784-
# async def reg_read(self, key_name: str, value_name='') -> str:
785-
# raise NotImplementedError()
786-
#
787-
# async def reg_set_view(self, reg_view: int) -> None:
788-
# raise NotImplementedError()
789-
#
790-
# async def reg_write(self, value_type: str, key_name: str, value_name='') -> None:
791-
# raise NotImplementedError()
792-
793775
async def run_script(self, script_text: str, decode: bool = True, blocking: bool = True, **runkwargs: Any) -> str:
794776
raise NotImplementedError()
795777

ahk/_async/transport.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def result(self, timeout: Optional[float] = None) -> T_SyncFuture:
6969
'AHKControlGetPos',
7070
'AHKControlGetText',
7171
'AHKControlSend',
72+
'AHKGetCoordMode',
7273
'AHKGetTitleMatchMode',
7374
'AHKGetTitleMatchSpeed',
7475
'AHKImageSearch',
@@ -82,6 +83,7 @@ def result(self, timeout: Optional[float] = None) -> T_SyncFuture:
8283
'AHKSendPlay',
8384
'AHKSendRaw',
8485
'AHKSetDetectHiddenWindows',
86+
'AHKSetCoordMode',
8587
'AHKSetTitleMatchMode',
8688
'AHKWinClose',
8789
'AHKWinExist',
@@ -448,6 +450,13 @@ async def function_call(self, function_name: Literal['AHKControlClick'], args: O
448450

449451
@overload
450452
async def function_call(self, function_name: Literal['AHKControlGetPos'], args: Optional[List[str]] = None, *, blocking: bool = True) -> Union[Tuple[int, int, int, int], AsyncFutureResult[Tuple[int, int, int, int]]]: ...
453+
454+
@overload
455+
async def function_call(self, function_name: Literal['AHKGetCoordMode'], args: List[str]) -> str: ...
456+
457+
@overload
458+
async def function_call(self, function_name: Literal['AHKSetCoordMode'], args: List[str]) -> None: ...
459+
451460
# @overload
452461
# async def function_call(self, function_name: Literal['HideTrayTip'], args: Optional[List[str]] = None) -> None: ...
453462
# @overload

ahk/_sync/engine.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,16 @@ def get_title_match_speed(self) -> str:
220220
resp = self._transport.function_call('AHKGetTitleMatchSpeed')
221221
return resp
222222

223+
def set_coord_mode(self, target: CoordModeTargets, relative_to: CoordModeRelativeTo = 'Screen') -> None:
224+
args = [str(target), str(relative_to)]
225+
self._transport.function_call('AHKSetCoordMode', args)
226+
return None
227+
228+
def get_coord_mode(self, target: CoordModeTargets) -> str:
229+
args = [str(target)]
230+
resp = self._transport.function_call('AHKGetCoordMode', args)
231+
return resp
232+
223233
# fmt: off
224234
@overload
225235
def control_click(self, *, button: Literal['L', 'R', 'M', 'LEFT', 'RIGHT', 'MIDDLE'] = 'L', click_count: int = 1, options: str = '', control: str = '', title: str = '', text: str = '', exclude_title: str = '', exclude_text: str = '', title_match_mode: Optional[TitleMatchMode] = None, detect_hidden_windows: Optional[bool] = None) -> None: ...
@@ -761,34 +771,6 @@ def key_wait(
761771
resp = self._transport.function_call('AHKKeyWait', args)
762772
return resp
763773

764-
# async def mouse_position(self):
765-
# raise NotImplementedError()
766-
767-
def mouse_wheel(
768-
self,
769-
direction: Union[
770-
Literal['up'], Literal['down'], Literal['UP'], Literal['DOWN'], Literal['Up'], Literal['Down']
771-
],
772-
*args: Any,
773-
**kwargs: Any,
774-
) -> None:
775-
raise NotImplementedError()
776-
777-
# async def reg_delete(self, key_name: str, value_name: str = '') -> None:
778-
# raise NotImplementedError()
779-
#
780-
# async def reg_loop(self, reg: str, key_name: str, mode=''):
781-
# raise NotImplementedError()
782-
#
783-
# async def reg_read(self, key_name: str, value_name='') -> str:
784-
# raise NotImplementedError()
785-
#
786-
# async def reg_set_view(self, reg_view: int) -> None:
787-
# raise NotImplementedError()
788-
#
789-
# async def reg_write(self, value_type: str, key_name: str, value_name='') -> None:
790-
# raise NotImplementedError()
791-
792774
def run_script(self, script_text: str, decode: bool = True, blocking: bool = True, **runkwargs: Any) -> str:
793775
raise NotImplementedError()
794776

@@ -2190,9 +2172,28 @@ def right_click(self, x: Optional[Union[int, Tuple[int, int]]] = None, y: Option
21902172
@overload
21912173
def right_click(self, x: Optional[Union[int, Tuple[int, int]]] = None, y: Optional[int] = None, *, click_count: Optional[int] = None, direction: Optional[Literal['U', 'D', 'Up', 'Down']] = None, relative: Optional[bool] = None, blocking: bool = True, coord_mode: Optional[CoordModeRelativeTo] = None) -> Union[None, FutureResult[None]]: ...
21922174
# fmt: on
2193-
def right_click(self, x: Optional[Union[int, Tuple[int, int]]] = None, y: Optional[int] = None, *, click_count: Optional[int] = None, direction: Optional[Literal['U', 'D', 'Up', 'Down']] = None, relative: Optional[bool] = None, blocking: bool = True, coord_mode: Optional[CoordModeRelativeTo] = None) -> Union[None, FutureResult[None]]:
2175+
def right_click(
2176+
self,
2177+
x: Optional[Union[int, Tuple[int, int]]] = None,
2178+
y: Optional[int] = None,
2179+
*,
2180+
click_count: Optional[int] = None,
2181+
direction: Optional[Literal['U', 'D', 'Up', 'Down']] = None,
2182+
relative: Optional[bool] = None,
2183+
blocking: bool = True,
2184+
coord_mode: Optional[CoordModeRelativeTo] = None,
2185+
) -> Union[None, FutureResult[None]]:
21942186
button = 'R'
2195-
return self.click(x, y, button=button, click_count=click_count, direction=direction, relative=relative, blocking=blocking, coord_mode=coord_mode)
2187+
return self.click(
2188+
x,
2189+
y,
2190+
button=button,
2191+
click_count=click_count,
2192+
direction=direction,
2193+
relative=relative,
2194+
blocking=blocking,
2195+
coord_mode=coord_mode,
2196+
)
21962197

21972198
# fmt: off
21982199
@overload

ahk/_sync/transport.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def result(self, timeout: Optional[float] = None) -> T_SyncFuture:
6161
'AHKControlGetPos',
6262
'AHKControlGetText',
6363
'AHKControlSend',
64+
'AHKGetCoordMode',
6465
'AHKGetTitleMatchMode',
6566
'AHKGetTitleMatchSpeed',
6667
'AHKImageSearch',
@@ -74,6 +75,7 @@ def result(self, timeout: Optional[float] = None) -> T_SyncFuture:
7475
'AHKSendPlay',
7576
'AHKSendRaw',
7677
'AHKSetDetectHiddenWindows',
78+
'AHKSetCoordMode',
7779
'AHKSetTitleMatchMode',
7880
'AHKWinClose',
7981
'AHKWinExist',
@@ -431,6 +433,13 @@ def function_call(self, function_name: Literal['AHKControlClick'], args: Optiona
431433

432434
@overload
433435
def function_call(self, function_name: Literal['AHKControlGetPos'], args: Optional[List[str]] = None, *, blocking: bool = True) -> Union[Tuple[int, int, int, int], FutureResult[Tuple[int, int, int, int]]]: ...
436+
437+
@overload
438+
def function_call(self, function_name: Literal['AHKGetCoordMode'], args: List[str]) -> str: ...
439+
440+
@overload
441+
def function_call(self, function_name: Literal['AHKSetCoordMode'], args: List[str]) -> None: ...
442+
434443
# @overload
435444
# async def function_call(self, function_name: Literal['HideTrayTip'], args: Optional[List[str]] = None) -> None: ...
436445
# @overload

ahk/daemon.ahk

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,37 @@ AHKClick(ByRef command) {
11761176

11771177
}
11781178

1179+
AHKGetCoordMode(ByRef command) {
1180+
global STRINGRESPONSEMESSAGE
1181+
global EXCEPTIONRESPONSEMESSAGE
1182+
target := command[2]
1183+
1184+
if (target = "ToolTip") {
1185+
return FormatResponse(STRINGRESPONSEMESSAGE, A_CoordModeToolTip)
1186+
}
1187+
if (target = "Pixel") {
1188+
return FormatResponse(STRINGRESPONSEMESSAGE, A_CoordModePixel)
1189+
}
1190+
if (target = "Mouse") {
1191+
return FormatResponse(STRINGRESPONSEMESSAGE, A_CoordModeMouse)
1192+
}
1193+
if (target = "Caret") {
1194+
return FormatResponse(STRINGRESPONSEMESSAGE, A_CoordModeCaret)
1195+
}
1196+
if (target = "Menu") {
1197+
return FormatResponse(STRINGRESPONSEMESSAGE, A_CoordModeMenu)
1198+
}
1199+
return FormatResponse(EXCEPTIONRESPONSEMESSAGE, "Invalid coord mode")
1200+
}
1201+
1202+
AHKSetCoordMode(ByRef command) {
1203+
target := command[2]
1204+
relative_to := command[3]
1205+
CoordMode, %target%, %relative_to%
1206+
1207+
return FormatNoValueResponse()
1208+
}
1209+
11791210
MouseClickDrag(ByRef command) {
11801211
button := command[2]
11811212
if (command.Length() = 6) {

0 commit comments

Comments
 (0)