Created
January 24, 2025 04:07
-
-
Save spyoungtech/185f8cb0603147f6e84fcc012b2cd96c to your computer and use it in GitHub Desktop.
AHK extenstion example with state changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ahk import AHK | |
from ahk.extensions import Extension | |
extension_script = '''\ | |
variables := {} | |
set_variable(varname, value) { | |
global variables | |
variables[(varname)] := value | |
return FormatNoValueResponse() | |
} | |
get_variable(varname) { | |
global variables | |
val := variables[(varname)] | |
return FormatResponse("ahk.message.StringResponseMessage", val) | |
} | |
''' | |
extension = Extension(script_text=extension_script) | |
@extension.register | |
def get_variable(ahk: AHK, varname: str) -> str: | |
return ahk.function_call('get_variable', [varname]) | |
@extension.register | |
def set_variable(ahk: AHK, varname: str, value: str) -> None: | |
ahk.function_call('set_variable', [varname, value]) | |
ahk = AHK(extensions=[extension], version='v1') | |
ahk.set_variable(varname='foo', value='bar') | |
print(ahk.get_variable('foo')) # 'bar' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment