Python and AutoHotKey
- Joe Glines
- Posts: 772
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Python and AutoHotKey
I saw this code https://code.google.com/p/pahk/ which allows you to use Python in AHK and I found a few posts on the other AutoHotKey forum like this one talking about using the Autohotkey.dll file http://www.autohotkey.com/board/topic/3 ... ntry646062
I've successfully created an AHK script and used Python in it as well as created a Python script using AutoHotKey but was curious if anybody has any examples they could share. Specifically one thing I have not been able to do is to have a Python program use a hotstring from AutoHotKey.
thanks!
Joe
I've successfully created an AHK script and used Python in it as well as created a Python script using AutoHotKey but was curious if anybody has any examples they could share. Specifically one thing I have not been able to do is to have a Python program use a hotstring from AutoHotKey.
thanks!
Joe
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Re: Python and AutoHotKey
Interesting... I havent tried this yet... Any code samples you mind sharing?
For Hotstrings... What have you tried?
Regards
For Hotstrings... What have you tried?
Regards
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
- Joe Glines
- Posts: 772
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Python and AutoHotKey
I have several that I will post. Just been swamped at work! I'll get to it this weekend.
Regards,
Joe
Regards,
Joe
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Re: Python and AutoHotKey
Sure, take your time!
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
- Joe Glines
- Posts: 772
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Python and AutoHotKey
Sorry for the delay in posting. Here is an example using AutoHotKey within Python
# Two examples using AutoHotKey from within Python
import win32com.client # Import library / module
dll = win32com.client.Dispatch("AutoHotkey.Script") #Creating DLL object?
dll.ahktextdll() #no idea what this is doing...
dll.ahkExec("Send,My title`n") #uses AutoHotKey to send keystrokes from within Python
dll.ahkExec("Send,second line") #same as above just giving the example twice
#~ Second example- showing a bit more cool things
dll.ahkExec("Send,^a") #Use AutoHotKey to send Control+A (select all)
dll.ahkExec("Send,^c") #use AutoHotKey to copy selected text
dll.ahkExec("Sleep, 1000") #calling sleep in AutoHotKey for 1 second
dll.ahkExec("msgbox %Clipboard%") #using AutoHotKey to show a Msgbox of the clipboard
dll.ahkExec("Click right 144, 155") #using AutoHotKeyto have a right click at specific location
# Two examples using AutoHotKey from within Python
import win32com.client # Import library / module
dll = win32com.client.Dispatch("AutoHotkey.Script") #Creating DLL object?
dll.ahktextdll() #no idea what this is doing...
dll.ahkExec("Send,My title`n") #uses AutoHotKey to send keystrokes from within Python
dll.ahkExec("Send,second line") #same as above just giving the example twice
#~ Second example- showing a bit more cool things
dll.ahkExec("Send,^a") #Use AutoHotKey to send Control+A (select all)
dll.ahkExec("Send,^c") #use AutoHotKey to copy selected text
dll.ahkExec("Sleep, 1000") #calling sleep in AutoHotKey for 1 second
dll.ahkExec("msgbox %Clipboard%") #using AutoHotKey to show a Msgbox of the clipboard
dll.ahkExec("Click right 144, 155") #using AutoHotKeyto have a right click at specific location
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
- Joe Glines
- Posts: 772
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Python and AutoHotKey
Here is another exmaple using AutoHotKey within a Python Script. My examples are showing concepts- I don't really use the below, just need the abilities
import win32com.client #Import Library
ahk = win32com.client.Dispatch("AutoHotkey.Script") # I'm not sure what this does and why I need it here and not in my other script
ahk.ahktextdll("","","") # again- no idea what this is
ahk.ahkExec("#t::Run B:\Diet.xls") # Win+T opens a file on my computer
# When the folliwing line is commented out, the below hotkey runs w/o pressing it, but then it works correctly. When I don't comment it out, the above hotkey will not work. I'd love to know how to have multiple hotkeys within one Python script
ahk.ahktextdll("","","")
ahk.ahkExec("^t::Run http://www.google.com") #Cntrl+t launches default browser to google
ahk.ahkExec("while 1\nSleep 100") #This (infininte loop) keeps script running- needs to be after the hotkey
#~ ahk.ahktextdll('#Persistent') #This doesn't keep it running as I'd hoped
#~ ahk.ahkExec('#Persistent') #This doesn't keep it running as I'd hoped
import win32com.client #Import Library
ahk = win32com.client.Dispatch("AutoHotkey.Script") # I'm not sure what this does and why I need it here and not in my other script
ahk.ahktextdll("","","") # again- no idea what this is
ahk.ahkExec("#t::Run B:\Diet.xls") # Win+T opens a file on my computer
# When the folliwing line is commented out, the below hotkey runs w/o pressing it, but then it works correctly. When I don't comment it out, the above hotkey will not work. I'd love to know how to have multiple hotkeys within one Python script
ahk.ahktextdll("","","")
ahk.ahkExec("^t::Run http://www.google.com") #Cntrl+t launches default browser to google
ahk.ahkExec("while 1\nSleep 100") #This (infininte loop) keeps script running- needs to be after the hotkey
#~ ahk.ahktextdll('#Persistent') #This doesn't keep it running as I'd hoped
#~ ahk.ahkExec('#Persistent') #This doesn't keep it running as I'd hoped
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
- Joe Glines
- Posts: 772
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Python and AutoHotKey
I found this script Python script here: https://code.google.com/p/pahk/
Which will use AutoHotKey to copy the clipoard's contect to a Python variable.
from pahk import Interpreter
from time import sleep
#this script definds a function that uses AutoHotKey to copy the clipboard's content
def get_clipboard():
ahk_interpreter = Interpreter()
ahk_script = '''#Persistent\nx = %clipboard%''' # Create a variable "x" which hold the clipboard data.
ahk_interpreter.execute_script(ahk_script)
sleep(0.5) #Let the thread warms up
clipboard = ahk_interpreter.var_get('x') #Get the value of the variable x in the current running script
ahk_interpreter.terminate() # Terminate the running script
del ahk_interpreter
return clipboard
print (get_clipboard())
sleep(30)
Which will use AutoHotKey to copy the clipoard's contect to a Python variable.
from pahk import Interpreter
from time import sleep
#this script definds a function that uses AutoHotKey to copy the clipboard's content
def get_clipboard():
ahk_interpreter = Interpreter()
ahk_script = '''#Persistent\nx = %clipboard%''' # Create a variable "x" which hold the clipboard data.
ahk_interpreter.execute_script(ahk_script)
sleep(0.5) #Let the thread warms up
clipboard = ahk_interpreter.var_get('x') #Get the value of the variable x in the current running script
ahk_interpreter.terminate() # Terminate the running script
del ahk_interpreter
return clipboard
print (get_clipboard())
sleep(30)
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Re: Python and AutoHotKey
This example uses AutoHotkey.dll COM Interface instead of loading dll and defining functions.
Note that the dll must be registred using regsvr32 to be able to load the dll via COM.
Note that the dll must be registred using regsvr32 to be able to load the dll via COM.
Code: Select all
import win32com.client # Import Library
import time # for time.sleep
ahk = win32com.client.Dispatch("AutoHotkey.Script") # same as ahk := ComObjCreate("AutoHotkey.Script")
ahk.ahktextdll("","","") # start an empty '#Persistent' script
# ahk.ahkExec("#t::Run B:\Diet.xls") # this code is not good since ahkExec is used to execute commands and not add code
ahk.addScript("#t::Run B:\Diet.xls") # add code to running script
# ahk.ahktextdll("","","") # this would exit previous script and start a new one (#Persistent).
ahk.addScript("^t::Run http://www.google.com") # add more code to running script
while true
time.sleep(10000)
- Joe Glines
- Posts: 772
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Python and AutoHotKey
Here is an example that I found here: http://www.autohotkey.com/board/topic/4 ... ntry390670
which runs Python from within AutoHotKey. (I get an error when I click the hotkey but Python does grab the computer name)
#SingleInstance, Force
^t::
i := python := ComObjCreate("Python.Interpreter")
i.Exec("import win32api")
r := i.Eval("win32api.GetComputerName()")
msgbox % r
which runs Python from within AutoHotKey. (I get an error when I click the hotkey but Python does grab the computer name)
#SingleInstance, Force
^t::
i := python := ComObjCreate("Python.Interpreter")
i.Exec("import win32api")
r := i.Eval("win32api.GetComputerName()")
msgbox % r
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
- Joe Glines
- Posts: 772
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Python and AutoHotKey
HotKeyIt- thank you for your input! I'm completely out of my league here and your help is very much appreciated!
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
- Joe Glines
- Posts: 772
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Python and AutoHotKey
BTW- I had to update the while true statement to:
while 1:
time.sleep(10000)
I believe I needed the colon for Python and while I think "while true:" works with Python 3.x, it doesn't work for me in Python 2.7
while 1:
time.sleep(10000)
I believe I needed the colon for Python and while I think "while true:" works with Python 3.x, it doesn't work for me in Python 2.7
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
- Joe Glines
- Posts: 772
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Python and AutoHotKey
Absolutely not! I'm learning it because "nobody" knows what AutoHotKey is thus it doesn't do any good having it on my resume. Even though everything I've done in Python I can do in AutoHotKey... The only really cool thing I did in Python that I haven't done in AutoHotKey is multi-threaded web scraping.
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Re: Python and AutoHotKey
Multi-Threading in AHK_H is very simple, it works by using multiple AutoHotkey.dll threads:Joe Glines wrote:The only really cool thing I did in Python that I haven't done in AutoHotKey is multi-threaded web scraping.
Code: Select all
Loop 3
dll%A_Index%:=AhkThread("Alias(download," getvar(download%A_Index%) ")`ndownload:=URLDownloadToVar(""https://www.google.de/?gws_rd=ssl#q=autohotkey" A_Index """)`n" CreateScript("URLDownloadToVar{}"))
While dll1.ahkReady() || dll3.ahkReady() || dll3.ahkReady()
Sleep 100
loop 3
Gui,Add,Edit,w480 h60,% download%A_Index%
Gui,Show
return
GuiClose:
ExitApp
URLDownloadToVar(url){
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
hObject.Open("GET",url)
hObject.Send()
return hObject.ResponseText
}
- Joe Glines
- Posts: 772
- Joined: 30 Sep 2013, 20:49
- Location: Dallas
- Contact:
Re: Python and AutoHotKey
@HotkeyIt Thanks! I'm a bit swamped at the moment but I look forward to checking this out!
Sign-up for the HK Newsletter
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
AHK Tutorials:Web Scraping | | Webservice APIs | AHK and Excel | Chrome | RegEx | Functions
Training: AHK Webinars Courses on AutoHotkey
YouTube
Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Re: Python and AutoHotKey
Google Calendar Command Line Interface
gcalcli is a Python application that allows you to access your Google Calendar(s) from a command line. It's easy to get your agenda, search for events, add new events, delete events, edit events, and even import those annoying ICS/vCal invites from Microsoft Exchange and/or other sources. Additionally, gcalcli can be used as a reminder service and execute any application you want when an event is coming up.
... just in case someone is looking for a challenge eg. to create an AHK wrapper based on the above mentioned options (c't 21/2017, Seite/page 156)
https://github.com/insanum/gcalcli
gcalcli is a Python application that allows you to access your Google Calendar(s) from a command line. It's easy to get your agenda, search for events, add new events, delete events, edit events, and even import those annoying ICS/vCal invites from Microsoft Exchange and/or other sources. Additionally, gcalcli can be used as a reminder service and execute any application you want when an event is coming up.
... just in case someone is looking for a challenge eg. to create an AHK wrapper based on the above mentioned options (c't 21/2017, Seite/page 156)
https://github.com/insanum/gcalcli