-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to call AHK built-in functions that don't use ()? #2
Comments
Thank you! The simplicity is the killer feature IMO. 😄
You have it correct. 😉 A little ironic since we're wrapping commands and this is ahk unwrapped 😅, but it's to a minimal degree at least 😁. I've also found that I often end up slightly embellishing them past simple wrappers, per-project, anyway. Users are also welcome to create themselves a re-usable "library" of course, or as-they-go. Thankfully I don't think it would be too long. Also thank you for pointing out something that needs explicitly added to the documentation. 👍 |
Awesome. I think it's best to keep these simple. You might consider adding a short example of passing multiple args (which took me a second to figure out as well 😄 ):
I've already wrapped MouseGetPos to return via Jxon_Dump MouseGetPos() {
MouseGetPos, OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, 1
result := [OutputVarX, OutputVarY, OutputVarWin, OutputVarControl]
return Jxon_Dump(result)
} @dataclass
class MouseGetPosResult:
x: int
y: int
window: str
control: str
def __post_init__(self):
self.x = int(self.x)
self.y = int(self.y)
def mouse_get_pos(self):
res = self.ahk.f("MouseGetPos")
return MouseGetPosResult(*json.loads(res)) And the useful FindText: class Finder:
def __init__(self):
self.ahk = Script(
"""
#Include ./lib/findtext.ahk
#Include ./lib/jxon.ahk
Search(window_title, search_arg, find_all) {
WinGetPos, pX, pY, pW, pH, %window_title%
if (result := FindText(outX, outY, pX, pY, pX+pW, pY+pH, 0.05, 0.05, search_arg,,find_all)) {
response := Jxon_Dump(result)
return response
} else {
response := Jxon_Dump("")
return response
}
}
"""
)
def __call__(self, window_title, needle: str, find_all: bool = False):
# validate/transform inputs
find_all = 1 if True else 0
result = self.ahk.f("Search", window_title, needle, str(find_all))
return json.loads(result)
finder = Finder() |
Whoops! Superb suggestion.
Love seeing things I've never tested ( 👍 |
Hi. I love the simplicity of what you've created here.
I might have missed it, but is there anyway to call build-ins that don't use parenthesis?
Currently I'm just creating my own functions to pass along:
So I then do:
ahk.f('WinActivate', self.title)
or
ahk.f('Click', f"{x} {y}")
Thanks!
The text was updated successfully, but these errors were encountered: