Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
set/get coord mode
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Nov 15, 2022
1 parent 4cd6be4 commit d75dcdc
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 58 deletions.
38 changes: 10 additions & 28 deletions ahk/_async/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ async def get_title_match_speed(self) -> str:
resp = await self._transport.function_call('AHKGetTitleMatchSpeed')
return resp

async def set_coord_mode(self, target: CoordModeTargets, relative_to: CoordModeRelativeTo = 'Screen') -> None:
args = [str(target), str(relative_to)]
await self._transport.function_call('AHKSetCoordMode', args)
return None

async def get_coord_mode(self, target: CoordModeTargets) -> str:
args = [str(target)]
resp = await self._transport.function_call('AHKGetCoordMode', args)
return resp

# fmt: off
@overload
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: ...
Expand Down Expand Up @@ -762,34 +772,6 @@ async def key_wait(
resp = await self._transport.function_call('AHKKeyWait', args)
return resp

# async def mouse_position(self):
# raise NotImplementedError()

async def mouse_wheel(
self,
direction: Union[
Literal['up'], Literal['down'], Literal['UP'], Literal['DOWN'], Literal['Up'], Literal['Down']
],
*args: Any,
**kwargs: Any,
) -> None:
raise NotImplementedError()

# async def reg_delete(self, key_name: str, value_name: str = '') -> None:
# raise NotImplementedError()
#
# async def reg_loop(self, reg: str, key_name: str, mode=''):
# raise NotImplementedError()
#
# async def reg_read(self, key_name: str, value_name='') -> str:
# raise NotImplementedError()
#
# async def reg_set_view(self, reg_view: int) -> None:
# raise NotImplementedError()
#
# async def reg_write(self, value_type: str, key_name: str, value_name='') -> None:
# raise NotImplementedError()

async def run_script(self, script_text: str, decode: bool = True, blocking: bool = True, **runkwargs: Any) -> str:
raise NotImplementedError()

Expand Down
9 changes: 9 additions & 0 deletions ahk/_async/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def result(self, timeout: Optional[float] = None) -> T_SyncFuture:
'AHKControlGetPos',
'AHKControlGetText',
'AHKControlSend',
'AHKGetCoordMode',
'AHKGetTitleMatchMode',
'AHKGetTitleMatchSpeed',
'AHKImageSearch',
Expand All @@ -82,6 +83,7 @@ def result(self, timeout: Optional[float] = None) -> T_SyncFuture:
'AHKSendPlay',
'AHKSendRaw',
'AHKSetDetectHiddenWindows',
'AHKSetCoordMode',
'AHKSetTitleMatchMode',
'AHKWinClose',
'AHKWinExist',
Expand Down Expand Up @@ -448,6 +450,13 @@ async def function_call(self, function_name: Literal['AHKControlClick'], args: O

@overload
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]]]: ...

@overload
async def function_call(self, function_name: Literal['AHKGetCoordMode'], args: List[str]) -> str: ...

@overload
async def function_call(self, function_name: Literal['AHKSetCoordMode'], args: List[str]) -> None: ...

# @overload
# async def function_call(self, function_name: Literal['HideTrayTip'], args: Optional[List[str]] = None) -> None: ...
# @overload
Expand Down
61 changes: 31 additions & 30 deletions ahk/_sync/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ def get_title_match_speed(self) -> str:
resp = self._transport.function_call('AHKGetTitleMatchSpeed')
return resp

def set_coord_mode(self, target: CoordModeTargets, relative_to: CoordModeRelativeTo = 'Screen') -> None:
args = [str(target), str(relative_to)]
self._transport.function_call('AHKSetCoordMode', args)
return None

def get_coord_mode(self, target: CoordModeTargets) -> str:
args = [str(target)]
resp = self._transport.function_call('AHKGetCoordMode', args)
return resp

# fmt: off
@overload
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: ...
Expand Down Expand Up @@ -761,34 +771,6 @@ def key_wait(
resp = self._transport.function_call('AHKKeyWait', args)
return resp

# async def mouse_position(self):
# raise NotImplementedError()

def mouse_wheel(
self,
direction: Union[
Literal['up'], Literal['down'], Literal['UP'], Literal['DOWN'], Literal['Up'], Literal['Down']
],
*args: Any,
**kwargs: Any,
) -> None:
raise NotImplementedError()

# async def reg_delete(self, key_name: str, value_name: str = '') -> None:
# raise NotImplementedError()
#
# async def reg_loop(self, reg: str, key_name: str, mode=''):
# raise NotImplementedError()
#
# async def reg_read(self, key_name: str, value_name='') -> str:
# raise NotImplementedError()
#
# async def reg_set_view(self, reg_view: int) -> None:
# raise NotImplementedError()
#
# async def reg_write(self, value_type: str, key_name: str, value_name='') -> None:
# raise NotImplementedError()

def run_script(self, script_text: str, decode: bool = True, blocking: bool = True, **runkwargs: Any) -> str:
raise NotImplementedError()

Expand Down Expand Up @@ -2190,9 +2172,28 @@ def right_click(self, x: Optional[Union[int, Tuple[int, int]]] = None, y: Option
@overload
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]]: ...
# fmt: on
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]]:
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]]:
button = 'R'
return self.click(x, y, button=button, click_count=click_count, direction=direction, relative=relative, blocking=blocking, coord_mode=coord_mode)
return self.click(
x,
y,
button=button,
click_count=click_count,
direction=direction,
relative=relative,
blocking=blocking,
coord_mode=coord_mode,
)

# fmt: off
@overload
Expand Down
9 changes: 9 additions & 0 deletions ahk/_sync/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def result(self, timeout: Optional[float] = None) -> T_SyncFuture:
'AHKControlGetPos',
'AHKControlGetText',
'AHKControlSend',
'AHKGetCoordMode',
'AHKGetTitleMatchMode',
'AHKGetTitleMatchSpeed',
'AHKImageSearch',
Expand All @@ -74,6 +75,7 @@ def result(self, timeout: Optional[float] = None) -> T_SyncFuture:
'AHKSendPlay',
'AHKSendRaw',
'AHKSetDetectHiddenWindows',
'AHKSetCoordMode',
'AHKSetTitleMatchMode',
'AHKWinClose',
'AHKWinExist',
Expand Down Expand Up @@ -431,6 +433,13 @@ def function_call(self, function_name: Literal['AHKControlClick'], args: Optiona

@overload
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]]]: ...

@overload
def function_call(self, function_name: Literal['AHKGetCoordMode'], args: List[str]) -> str: ...

@overload
def function_call(self, function_name: Literal['AHKSetCoordMode'], args: List[str]) -> None: ...

# @overload
# async def function_call(self, function_name: Literal['HideTrayTip'], args: Optional[List[str]] = None) -> None: ...
# @overload
Expand Down
31 changes: 31 additions & 0 deletions ahk/daemon.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,37 @@ AHKClick(ByRef command) {

}

AHKGetCoordMode(ByRef command) {
global STRINGRESPONSEMESSAGE
global EXCEPTIONRESPONSEMESSAGE
target := command[2]

if (target = "ToolTip") {
return FormatResponse(STRINGRESPONSEMESSAGE, A_CoordModeToolTip)
}
if (target = "Pixel") {
return FormatResponse(STRINGRESPONSEMESSAGE, A_CoordModePixel)
}
if (target = "Mouse") {
return FormatResponse(STRINGRESPONSEMESSAGE, A_CoordModeMouse)
}
if (target = "Caret") {
return FormatResponse(STRINGRESPONSEMESSAGE, A_CoordModeCaret)
}
if (target = "Menu") {
return FormatResponse(STRINGRESPONSEMESSAGE, A_CoordModeMenu)
}
return FormatResponse(EXCEPTIONRESPONSEMESSAGE, "Invalid coord mode")
}

AHKSetCoordMode(ByRef command) {
target := command[2]
relative_to := command[3]
CoordMode, %target%, %relative_to%

return FormatNoValueResponse()
}

MouseClickDrag(ByRef command) {
button := command[2]
if (command.Length() = 6) {
Expand Down

0 comments on commit d75dcdc

Please sign in to comment.