开发者

Communicating between Autohotkey and python

Is there a way to send some parameter from autohotkey to python.

Using Autohot key I read some number from the notepad and store in a variable and now I want to send this number to the python code in order to do some calculations.

My Autohotkey code is:

controlGetText, telphoneN开发者_运维知识库umber, Edit1, Untitled - Notepad

And I want to send this telphoneNumber to python file.

Is there a way I can do that?

Do I need to create an exe file of a python and then call from autohotkey? For example:

RunWait,  C:\Button\button.exe telphoneNumber

Or do I need to run command prompt commands from autohotkey to run python program? Something like:

Run Cmd Python  C:\Button\button.py telphoneNumber

I do not know which is the best way as I am newbie in Autohotkey.

Any suggestion will be appreciated.

EDIT:

However I succeded in sending parameter by using run command from autohotkey, which will execute the python file from command prompt.

Run Cmd \k "Python  C:\Button\button.py %telphoneNumber%"

But still want to know if this is the right solution, or if there are others?


Inter-process communication would be capable of sending the information while the Python script is already running.

Forum thread: http://www.autohotkey.com/forum/topic21699.html (there's a nice documentation link in that post)

You could also use TCP/IP Network communication (like in the post below), but that probably wouldn't be quite as slick as using IPC.

Forum thread: http://www.autohotkey.com/forum/topic13829.html


The way you got it working is the easiest, and probably best, method of accomplishing what you want.

Communication between applications can be done with more methods then you probably can imagine, but as long as it doesn't have to be realtime you can call your programs with arguments, as it is easy and reliable.


Python COM server allows directly calling Python functions(with args and return) using AHK.
you use it like this: MsgBox % pythonComServer.method(args)

You do not need to have a python script already running.
ComObjCreate() will instantiate an instance of python.

I don't know how the inter-process communication is done in the background by pywin32, but using it is simple.

2 examples here: Call python function with arguments and get returned value in autohotkey

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜