Page 1 of 1

How to combine autohotkey dll with Python?

Posted: 31 May 2019, 22:08
by bsayles
I'm new to writing hotkeys through Autohotkey dll. I've been trying to combine autohotkey dll with Python's ahk module. But every time I write hotkeys, I get various errors. Do you have an example or tutorial on how the code for keyboard hotkeys is suppose to work through autohotkey dll? Thanks for your help.


[Mod edit: Topic name added]

Re: How to combine autohotkey dll with Python?

Posted: 01 Jun 2019, 06:35
by HotKeyIt
It is the same as in AutoHotkey.exe.
Can you show your examples and what errors do you get?

Re: How to combine autohotkey dll with Python?

Posted: 01 Jun 2019, 15:07
by bsayles
ahk = AHK(executable_path = r'C:\Users\bryan\AppData\Local\Programs\Python\Python37-32\ahkdll-v2-release-master\x64w_MT\AutoHotkey.dll')

def hotkeys ():
if ahk.key_press('Control', 'Shift', 'z'):
ahk.execute(ahk.key_press('m'))

elif ahk.key_press('Control', 'Shift', 'x'):
ahk.execute(ahk.key_press('f'))

elif ahk.key_press('Control', 'Shift', 'c'):
ahk.execute(ahk.key_press('u'))

It's always syntax errors. i know that that usually means I missed something on the lines before it, but I fixed those errors and I'm still getting the syntax error. Any idea what is wrong? I've tried to do it with the autohotkey.exe but neither seems to work. Thanks for your help.

Re: How to combine autohotkey dll with Python?

Posted: 01 Jun 2019, 18:10
by HotKeyIt
Where did you get that code from?
CAn you link to the py library you are using.

Re: How to combine autohotkey dll with Python?

Posted: 01 Jun 2019, 19:55
by bsayles
sure. the py module I'm using is from ahk import AHK. It's in Python 3. How should this be written? I'm new to AHK. Thanks for your help.

Re: How to combine autohotkey dll with Python?

Posted: 01 Jun 2019, 20:25
by swagfag
https://github.com/spyoungtech/ahk
all this lib can do is write out a temp ahk file and run it. it doesnt interface with ahk.dll or anything

what u need is to find ur python equivalent of https://docs.microsoft.com/en-us/windows/desktop/api/libloaderapi/nf-libloaderapi-loadlibrarya and https://docs.microsoft.com/en-us/windows/desktop/api/libloaderapi/nf-libloaderapi-getprocaddress
get some function pointers to the thread functions https://hotkeyit.github.io/v2/docs/commands/AhkThread.htm
write ur ahk script with ahk functions in a string and launch the string as a new thread

Re: How to combine autohotkey dll with Python?

Posted: 02 Jun 2019, 05:04
by HotKeyIt