AutoHotkey Community

It is currently May 27th, 2012, 6:12 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: January 26th, 2010, 8:29 pm 
Offline

Joined: July 6th, 2009, 9:58 pm
Posts: 678
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2010, 11:47 pm 
Minimum I would have expected that you link to that AutoHotkey.dll ...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2010, 11:53 pm 
Offline

Joined: July 6th, 2009, 9:58 pm
Posts: 678
Of course, here's the website:
http://www.autohotkey.net/~tinku99/ahkdll/

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2010, 12:26 am 
Offline

Joined: July 15th, 2007, 1:43 am
Posts: 1320
randallf wrote:


No, he means you would have to link it to your Python script.

_________________
Religion is false. >_>


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2010, 12:34 am 
Offline

Joined: July 6th, 2009, 9:58 pm
Posts: 678
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject: embed python
PostPosted: January 27th, 2010, 12:41 am 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
look here


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2010, 3:30 pm 
Offline

Joined: July 6th, 2009, 9:58 pm
Posts: 678
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?


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 27th, 2010, 6:30 pm 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2010, 6:40 pm 
Offline

Joined: July 6th, 2009, 9:58 pm
Posts: 678
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2010, 2:57 pm 
Offline

Joined: August 18th, 2009, 12:07 pm
Posts: 375
Location: holland
could someone give a much simpler example?!
eg sending "hello world" to notepad using ahk via python script


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2010, 3:03 pm 
Offline

Joined: August 28th, 2009, 11:17 am
Posts: 599
Location: Brighton, UK
Can you get any simpler than tinku99 wrote?

_________________
With mixed feelings I am stepping down from all moderation responsibilities: http://www.autohotkey.com/forum/viewtopic.php?t=82906


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2010, 3:06 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2010, 3:42 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Here are some more non COM examples ;)

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2010, 7:38 pm 
Offline

Joined: July 6th, 2009, 9:58 pm
Posts: 678
HotKeyIt wrote:
Here are some more non COM examples ;)


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.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: December 28th, 2010, 11:51 pm 
Offline

Joined: August 3rd, 2007, 8:01 am
Posts: 555
Location: Houston, TX
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")


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google Feedfetcher, HotkeyStick, Wicked and 56 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group