AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

AutoHotKey.dll with python
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
randallf



Joined: 06 Jul 2009
Posts: 678

PostPosted: Tue Jan 26, 2010 7:29 pm    Post subject: AutoHotKey.dll with python Reply with quote

Hello,

I am an AHK addict (basically all that I know at this point except some C) and I need to get into Python to go to the next level.

I simply do not have enough ability in Python to know how to use autohotkey.dll really at all - I cannot re-write everything that AHK can do in python either and I don't have the time to independently learn python - I need to combine the two in a way that lets me do everything I am already doing in AHK (for windows automation) in python so I can start to add python to what I'm doing...

Can anyone show me a very basic example of a python script that uses autohotkey.dll to activate a window using AHK's winactivate command? It would be helpful if this example showed how multiple parameters are passed.

Thank you very much!
Back to top
View user's profile Send private message
Murx
Guest





PostPosted: Tue Jan 26, 2010 10:47 pm    Post subject: Reply with quote

Minimum I would have expected that you link to that AutoHotkey.dll ...
Back to top
randallf



Joined: 06 Jul 2009
Posts: 678

PostPosted: Tue Jan 26, 2010 10:53 pm    Post subject: Reply with quote

Of course, here's the website:
http://www.autohotkey.net/~tinku99/ahkdll/

And the thread:
http://www.autohotkey.com/forum/topic43049.html
Back to top
View user's profile Send private message
trik



Joined: 15 Jul 2007
Posts: 1320

PostPosted: Tue Jan 26, 2010 11:26 pm    Post subject: Reply with quote

randallf wrote:
Of course, here's the website:
http://www.autohotkey.net/~tinku99/ahkdll/

And the thread:
http://www.autohotkey.com/forum/topic43049.html


No, he means you would have to link it to your Python script.
_________________
Religion is false. >_>
Back to top
View user's profile Send private message
randallf



Joined: 06 Jul 2009
Posts: 678

PostPosted: Tue Jan 26, 2010 11:34 pm    Post subject: Reply with quote

I understand what you mean, but I don't understand by what methods this is done.

>>>
command that includes library
CallToDLL (ahk command,?, ?, ?)

I am just looking for a super basic example that works to get started on.

ATM I don't know anything more than automating windows with AHK and basic concepts like functions/regex/expressions and some C stuff like reading hex and binary etc, the practical use of the advanced stuff gets over my head so I'm trying to find a familiar starting point that I can add from.

I figured this was a question that the right reader could answer in a few seconds, sorry for being so nub but I am just searching for a starting point.

Thanks for your time guys
Back to top
View user's profile Send private message
tinku99



Joined: 03 Aug 2007
Posts: 513
Location: Houston, TX

PostPosted: Tue Jan 26, 2010 11:41 pm    Post subject: embed python Reply with quote

look here
Back to top
View user's profile Send private message Send e-mail Visit poster's website
randallf



Joined: 06 Jul 2009
Posts: 678

PostPosted: Wed Jan 27, 2010 2:30 pm    Post subject: Reply with quote

After loads of searching I found this blurb:

Quote:
If you are using C# or another .NET language, you are probably better off with IronAhk. This AutoHotkey.dll allows other programs to host AutoHotkey scripts, but does not (yet?) expose commands/functions directly to other languages.


So to restate, what I am searching for is a way to execute AHK commands from a Python script. Is this possible?
Back to top
View user's profile Send private message
tinku99



Joined: 03 Aug 2007
Posts: 513
Location: Houston, TX

PostPosted: Wed Jan 27, 2010 5:30 pm    Post subject: embed autohotkey in python example Reply with quote

randallf wrote:
I am searching for is a way to execute AHK commands from a Python script. Is this possible?

Yes. Here is an example.
tested with python2.6, requires AutoHotkey.dll in the working directory or path...
ahkpython.py:
Code:
from ctypes import *

ahk = cdll.AutoHotkey
pyclient = create_string_buffer("ahkpython.ahk")   # no unicode in ahk

CMPFUNC = CFUNCTYPE(c_int, c_int)
def py_cmp_func(a):
     print "ahk: " , a
     return a

cmp_func = CMPFUNC(py_cmp_func)
fx = create_string_buffer(str(cast(cmp_func, c_void_p).value))

script = create_string_buffer("""
fx2(msg){
WinActivate %msg%
msgbox in function fx2 with %msg% from python
return "success"
}
""")
ahk.ahkdll(pyclient, "", fx)
ahk.ahkassign(create_string_buffer("fx"), fx)
ahk.addScript(script)
ahk.ahkFunction(create_string_buffer("fx2"), create_string_buffer("Untitled"))
ahkpython.ahk
Code:
#Persistent
dllcall(A_ScriptParams, "int", 42, "cdecl int")
return

f1::
inputbox, x, enter a numerical parameter for python callback
result := dllcall(A_ScriptParams, "int", x, "cdecl int")
return

remarks:
create_string_buffer is required because autohotkey.dll exported functions do not work with unicode.
See HotkeyIt's excellent chm help file for documentation on the functions.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
randallf



Joined: 06 Jul 2009
Posts: 678

PostPosted: Wed Jan 27, 2010 5:40 pm    Post subject: Reply with quote

T H A N K Y O U ! ! ! so much... this is what I was after. I have a lot to learn but now that I have the basics I believe have a resource for that.

Thanks, Tinku. Thanku.
Back to top
View user's profile Send private message
Chicken Pie 4 Tea



Joined: 18 Aug 2009
Posts: 375
Location: holland

PostPosted: Mon Nov 08, 2010 1:57 pm    Post subject: Reply with quote

could someone give a much simpler example?!
eg sending "hello world" to notepad using ahk via python script
Back to top
View user's profile Send private message
MacroMan!



Joined: 28 Aug 2009
Posts: 595
Location: Brighton, UK

PostPosted: Mon Nov 08, 2010 2:03 pm    Post subject: Reply with quote

Can you get any simpler than tinku99 wrote?
_________________
I'm still here.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
a4u
Guest





PostPosted: Mon Nov 08, 2010 2:06 pm    Post subject: Reply with quote

The AutoHotkey.dll now has a COM interface. I'd recommend using that if you want a simpler way to work with the DLL in python.
Back to top
HotKeyIt



Joined: 18 Jun 2008
Posts: 4652
Location: AHK Forum

PostPosted: Mon Nov 08, 2010 2:42 pm    Post subject: Reply with quote

Here are some more non COM examples Wink
_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
randallf



Joined: 06 Jul 2009
Posts: 678

PostPosted: Mon Nov 08, 2010 6:38 pm    Post subject: Reply with quote

HotKeyIt wrote:
Here are some more non COM examples Wink


Thank you! I haven't got back to this yet as my job led me more to VBA but I definitely am coming back here at some point.
Back to top
View user's profile Send private message
tinku99



Joined: 03 Aug 2007
Posts: 513
Location: Houston, TX

PostPosted: Tue Dec 28, 2010 10:51 pm    Post subject: python autohotkey com example Reply with quote

a4u wrote:
The AutoHotkey.dll now has a COM interface. I'd recommend using that if you want a simpler way to work with the DLL in python.
Here you go:
Code:
import win32com.client
dll = win32com.client.Dispatch("AutoHotkey.Script")
dll.ahktextdll()
dll.ahkExec("a=_Hello World!")
dll.ahkExec("StringTrimLeft,a,a,1")
dll.ahkgetvar("a")
dll.ahkExec("msgbox " + dll.ahkgetvar("a"))

requires: regsvr32.exe c:\pathtoahkdll\Win32w\AutoHotkey.dll
requires: pythonwin32, i use pythonxy
reference

@HotkeyIt:
1. can you provide the type library for autohotkey com interface as well ?
2. Is it possible to return safearrays (ComObjArray) using ahkgetvar(varname) ?
So we can do something like this from python:
Code:
code = '''
arr := ComObjArray(VT_VARIANT:=12, 3)
arr[0] := "Auto"
arr[1] := "Hot"
arr[2] := "key"
'''
dll.ahkExec(code)
dll.ahkgetvar("arr")
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group