AutoHotkey Community

It is currently May 27th, 2012, 9:33 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: August 31st, 2006, 1:15 pm 
Offline

Joined: August 31st, 2006, 1:09 pm
Posts: 3
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2006, 1:18 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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 ... 90478.aspx
http://www.codeproject.com/useritems/fast_ipc.asp

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher, nomissenrojb, Stigg and 19 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