{"id":9685,"date":"2023-07-28T22:57:20","date_gmt":"2023-07-28T22:57:20","guid":{"rendered":"https:\/\/max-drake.cc\/?p=9685"},"modified":"2023-07-28T22:57:27","modified_gmt":"2023-07-28T22:57:27","slug":"activate-python-scripts-from-autohotkey-v2-hotkeys","status":"publish","type":"post","link":"https:\/\/max-drake.cc\/?p=9685","title":{"rendered":"Activate Python Scripts from AutoHotKey V2 Hotkeys"},"content":{"rendered":"\n<p>I want to be able to activate some python scripts using keyboard hotkeys. That is, you type a hotkey , eg Alt + H and it runs the python script that you want.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Activate Python Scripts from AutoHotKey V2 Hotkeys\" width=\"678\" height=\"381\" data-src=\"https:\/\/www.youtube.com\/embed\/QYxTI81FtWI?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><br>You can do this with a Python script, running in the background and listening for the correct hotkey and then it will activate the specified python script.<br>I consider python a bigger program than AutoHotKey , about 4 times as large in Executable file size, so its using more PC resources to listen for the hotkeys.<br>In the past I\u2019ve used AutoHotKeys to run scripts on my PC. AutoHotKeys is a windows based program, so not any good for Linux or iOS. But since I run on Windows only I\u2019m more than happy to use AutoHotKeys to trigger programs and scripts.<br>AutoHotKey has now made V2 its current version, it is not backward compatible with V1, so I was interested in trying out using AHK v2 on a project.<br>It took a little bit of fiddling to get the v2 code to work, but I was pleased with the result.<br>On testing the resources from a python hotkey script and a AutoHotKey hotkey script the AutoHotKey script used about a quarter of memory resources to do the same sort of function.<br>You can download the files from this link:<br>https:\/\/drive.google.com\/drive\/folders\/19kI7VYI6ubJ5HRi8uAnR3OyCuhk70yFD?usp=sharing<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">End comment <\/h3>\n\n\n\n<p>This took me a while to get my head around the differences between AutoHotKey version 1 and 2. After persevering I finally got something running. <\/p>\n\n\n\n<p>The objective was to look at different ways to trigger python scripts, and this seemed like a logical method as I use AutoHotKey for most of my other hotkeys (as well as aText, which is especially useful for prototyping)<\/p>\n\n\n\n<p>At the end I had the functionality but felt I hadn&#8217;t satisfied myself that this was the best way to trigger python scripts, using a different program. So I made another video for doing it totally in python. There is a further article on that. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I want to be able to activate some python scripts using keyboard hotkeys. That is, you type a hotkey , eg Alt + H and it runs the python script that you want. You can do this with a Python script, running in the background and listening for the correct hotkey and then it will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9686,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[466,204,42,34],"tags":[],"class_list":["post-9685","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-autohotkey","category-automation","category-productivity","category-python"],"featured_image_src":"https:\/\/max-drake.cc\/wp-content\/uploads\/2023\/07\/mqdefault.jpg","featured_image_src_square":"https:\/\/max-drake.cc\/wp-content\/uploads\/2023\/07\/mqdefault.jpg","author_info":{"display_name":"Max Drake","author_link":"https:\/\/max-drake.cc\/?author=1"},"_links":{"self":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/posts\/9685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9685"}],"version-history":[{"count":1,"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/posts\/9685\/revisions"}],"predecessor-version":[{"id":9687,"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/posts\/9685\/revisions\/9687"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/media\/9686"}],"wp:attachment":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}