 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
nanobyte
Joined: 31 Aug 2006 Posts: 3
|
Posted: Thu Aug 31, 2006 12:15 pm Post subject: Easy AutoHotKey <-> Python communication |
|
|
If you have the Win32 extensions of Python (are automatically installed with ActivePython AFAIK), it is easy to access the clipboard, and thus easy to communicate with AutoHotKey (in both directions).
I now only use AHK for the most basic GUI automation/hotkey tasks and delegate anything more fancy (string manipulation, for example) to Python. Here is a simple Python module that provides the required clipboard functionality:
import win32clipboard as cp
import win32con
def get_clipboard():
cp.OpenClipboard()
result = cp.GetClipboardData(win32con.CF_TEXT)
cp.CloseClipboard()
return result
def set_clipboard(what):
cp.OpenClipboard()
cp.EmptyClipboard()
cp.SetClipboardData(win32con.CF_TEXT, what)
cp.CloseClipboard()
def test():
set_clipboard("The matrix got you.")
print get_clipboard()
if __name__ == '__main__':
test()
Now if you create a Python module that accesses the clipboard on startup and manipulates it, you can easily use the AHK Run command to quickly manipulate anything that is in the clipboard.
I mainly use AHK + Python to work with C# code - e.g. automatically providing a property skeleton for the highlighted field. Works fine!
Happy AHK'ing! |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Thu Aug 31, 2006 12:18 pm Post subject: |
|
|
Interesting...
Using the clipboard to communicate between two programs can be OK, but can be also disruptive if your programs run in the background while you try to work, eg. with a text editor...
Perhaps using something like shared memory (or even a temporary file) would work better. Or perhaps SendMessage...
Of course, most alternatives need some DllCalls on the AHK side.
For my (and others) reference:
http://windowssdk.msdn.microsoft.com/en-us/library/ms690478.aspx
http://www.codeproject.com/useritems/fast_ipc.asp _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|