Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Running AHK with python


  • Please log in to reply
3 replies to this topic
cptjacksparra
  • Members
  • 2 posts
  • Last active: Jun 25 2012 09:07 AM
  • Joined: 25 Jun 2012
Hi all, i've looked around bit i can't seem to get any code i've found elsewhere working

I'm trying to execute an ahk script via python.

I've downloaded the <!-- m -->https://ahknet.autoh.../AutoHotkey.zip<!-- m --> but i'm not sure whether or not to use the files from the "Win32w" or "Win32a" folders. Similarly, can i just put all those files in the same folder as my scripts?

I'm using python 2.7

so i guess i'm asking, how do i run a .ahk file in the same folder as my python file, via python.

pythoncode.py:
import ctypes,time
import os, sys

ahk = ctypes.cdll.AutoHotkey
ahk.ahktextdll("") #start script in persistent mode (wait for action)
ahk.ahkdll("ahkTestScript.ahk","","")

ahkTestScript.ahk:
Run Notepad

edit: when i run via IDLE, i get the following error:
"WindowsError: exception: access violation reading 0x00000004"
at the line: ahk.ahktextdll("")

Any help would be appreciated.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
You will need to save AutoHotkey.dll from Win32a folder in %A_WinDir%\system32 or python app folder (at least on my protable python).

You do not need that line because ahkdll() will restart the thread anyway.
You only need it if you want to start empty script.

In any case you will always need to pass all parameters.
ahk.ahktextdll(""[color=#FF0000],"",""[/color]) [color=#40BF80]#start script in persistent mode (wait for action)[/color]


cptjacksparra
  • Members
  • 2 posts
  • Last active: Jun 25 2012 09:07 AM
  • Joined: 25 Jun 2012

You will need to save AutoHotkey.dll from Win32a folder in %A_WinDir%\system32 or python app folder (at least on my protable python).

You do not need that line because ahkdll() will restart the thread anyway.
You only need it if you want to start empty script.

In any case you will always need to pass all parameters.

ahk.ahktextdll(""[color=#FF0000],"",""[/color]) [color=#40BF80]#start script in persistent mode (wait for action)[/color]


Thanks for the reply

It still doesnt appear to be working, when i run the program it says "do you want ot create a new file 整瑳牥愮歨" with weird characters.

import ctypes,time
import os, sys

ahk = ctypes.cdll.AutoHotkey
ahk.ahktextdll("","","") #start script in persistent mode (wait for action)
ahk.ahkdll("ahkTestScript.ahk","","")


HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
That is because you have taken AutoHotkey.dll from Win32w folder, as far as I know python 2 does not support Unicode yet.
import ctypes,time
import os, sys

ahk = ctypes.cdll.AutoHotkey
#ahk.ahktextdll("","","") #this line is useless, because the line below will exit this script!
ahk.ahkdll("ahkTestScript.ahk","","")