{"id":7327,"date":"2021-10-01T19:33:34","date_gmt":"2021-10-01T19:33:34","guid":{"rendered":"https:\/\/max-drake.cc\/?p=7327"},"modified":"2021-10-02T02:06:14","modified_gmt":"2021-10-02T02:06:14","slug":"ahk-versions-1-2-in-vs-code","status":"publish","type":"post","link":"https:\/\/max-drake.cc\/?p=7327","title":{"rendered":"AHK versions 1 &#038; 2 in VS Code"},"content":{"rendered":"\n<p>I was watching an AutoHotKey video and Version 2 was mentioned, and the fact that it is not backward compatible with Version 1. It is currently in beta stage and its a zip file so you can install it anywhere. <\/p>\n\n\n\n<p>I&#8217;m a bit confused about versioning as the current release (v1) has an L next to it, I think this was when they brought out a 64 bit version, so there is the original, the later version and now a version 2. Hmmm!<\/p>\n\n\n\n<p>Anyway I downloaded it and installed it and watched a couple of videos by Tab Nation. In the first he puts the desktop icon file onto the desktop icon of V2 AHK to run, but he then did another video..<\/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=\"AutoHotkey V2 - Intro to Version 2 AHK - Install and First Script\" width=\"678\" height=\"381\" data-src=\"https:\/\/www.youtube.com\/embed\/QC74IIWYosU?list=PLfHPAKSz_DJrrM_mNBGtyl7i_V5uKjlya\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>Where he renamed the extension to .AHK2 or .AH2 and then associated those extensions with AutoHotKey  Version 2 .exe.<\/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=\"AutoHotkey v2 - .ahk vs .ahk2 -How to run scripts in v1 vs v2 the easy way\" width=\"678\" height=\"381\" data-src=\"https:\/\/www.youtube.com\/embed\/juE0o2Y2JXU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>So that was great, you could then run either version on the same PC. I then wanted to be able to use the same code editor, in my case VS Code to be able to run either version. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">VS Code setup<\/h3>\n\n\n\n<p>On looking<strong><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=zero-plusplus.vscode-autohotkey-debug\" target=\"_blank\" rel=\"noreferrer noopener\"> at VS Code extensions there was one for V1 and one for V2. Also there was a AHK debugger &#8220;vscode-autohotkey-debug<\/a><\/strong>&#8221; by Zero-plusplus- <strong>Advanced debugging support for AutoHotkey(includes H) v1 and v2<\/strong><\/p>\n\n\n\n<p>So you can debug and run both versions. <\/p>\n\n\n\n<p><strong>This extension will not work alone.<\/strong> A separate extension that supports the AutoHotkey language is required(The most famous is <a rel=\"noreferrer noopener\" href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=slevesque.vscode-autohotkey\" target=\"_blank\">slevesque.vscode-autohotkey<\/a>). If you are using AutoHotkey v2, another extension that supports it required. (e.g. <a rel=\"noreferrer noopener\" href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=dudelmoser.vscode-autohotkey2\" target=\"_blank\">dudelmoser.vscode-autohotkey2<\/a>).<\/p>\n\n\n\n<p>The way it does it is with the launch.json file it has in your <code>${workspaceFolder}<\/code>. This being where you have whichever version of code you are running. <\/p>\n\n\n\n<p>So I have 2 directories AHK-Working &amp; AHK-V2-Working, so I can separate the 2 version codes. Ineach of these directories is a .vscode directory and in that is a  launch.json  file that sets up the configuration for running files in that particular directory. <\/p>\n\n\n\n<p>I also moved my v2 AHK files to <code>C:\/Program Files\/AutoHotkey<\/code>\/<code>v2\/AutoHotkey.exe<\/code> and I copied and renamed the  <code>AutoHotkey64.exe<\/code> to just  <code>AutoHotkey.exe<\/code>  (that is what it calls in the C:\/Program Files\/AutoHotkey.exe for the v1 code. <\/p>\n\n\n\n<p>So when you open a file in a specific directory, it will look for the  launch.json file to see how it should be setup and which runtime program to use.  The code below looks simple ,and the basic settings table looks simple (https:\/\/marketplace.visualstudio.com\/items?itemName=zero-plusplus.vscode-autohotkey-debug#usage) but it took me a few hours for 3 days before I got the configuration below to work for both instances. <\/p>\n\n\n\n<p>I&#8217;ve yet to check out the .ah2 extension, I may have to add a complete block for that also. <\/p>\n\n\n\n<p>Another thing, as  launch.json  is JS notation you need to be careful with commas, especially at end of 2nd block and last item in list (they don&#8217;t have them). <\/p>\n\n\n\n<p>This can be used as the <strong>.vscode\\ launch.json<\/strong> file in both the  2 directories <strong>AHK-Working<\/strong> &amp; A<strong>HK-V2-Working<\/strong> for both versions. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    \/\/launch.json\n{\n    {\n        \"configurations\": &#91;\n            {\n                \"name\": \"AutoHotkey1 Debug\",\n                \"type\": \"autohotkey\",\n                \"program\":\"${file}\",\n                \"request\": \"launch\",\n                \"runtimeArgs_v1\":&#91;\".ahk\"],\n                \"port\":\"9003\",\n                \"runtime_v1\": \"AutoHotkey.exe\",\n                \"runtimeArgs\":&#91; \"\/ErrorStdOut=UTF-8\"]\n                \n            },\n            {\n                \"name\": \"AutoHotkey2 Debug\",\n                \"type\": \"autohotkey\",\n                \"request\": \"launch\",\n                \"program\":\"${file}\",\n                \"runtimeArgs_v2\":&#91;\".ah2\"],\n                \"runtime_v2\": \"v2\/AutoHotkey64.exe\",\n                \"runtimeArgs\":&#91; \"\/ErrorStdOut=UTF-8\"]\n                        },\n            {\n                 \"name\": \"AutoHotkey2 Debug\",\n                \"type\": \"autohotkey\",\n                \"request\": \"launch\",\n                \"runtimeArgs_v2\":&#91;\".ahk2\"],\n                \"port\":\"9010\",\n                \"runtime_v2\": \"v2\/AutoHotkey64.exe\",\n                \"program\":\"${file}\",\n                \"runtimeArgs\":&#91; \"\/ErrorStdOut=UTF-8\"]\n                 }\n    ]\n}<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"722\" height=\"134\" data-src=\"https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/1-1.jpg\" alt=\"\" class=\"wp-image-7336 lazyload\" data-srcset=\"https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/1-1.jpg 722w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/1-1-300x56.jpg 300w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/1-1-50x9.jpg 50w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/1-1-269x50.jpg 269w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/1-1-100x19.jpg 100w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/1-1-539x100.jpg 539w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/1-1-640x119.jpg 640w\" data-sizes=\"(max-width: 722px) 100vw, 722px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 722px; --smush-placeholder-aspect-ratio: 722\/134;\" \/><\/figure><\/div>\n\n\n\n<p>In image above the .ahk file is being run by the v1 AHK program<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img decoding=\"async\" data-src=\"https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/2.jpg\" alt=\"\" class=\"wp-image-7334 lazyload\" width=\"729\" height=\"115\" data-srcset=\"https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/2.jpg 729w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/2-300x47.jpg 300w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/2-50x8.jpg 50w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/2-317x50.jpg 317w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/2-100x16.jpg 100w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/2-634x100.jpg 634w, https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/2-640x101.jpg 640w\" data-sizes=\"(max-width: 729px) 100vw, 729px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 729px; --smush-placeholder-aspect-ratio: 729\/115;\" \/><\/figure><\/div>\n\n\n\n<p> In image above the .ahk2 file is being run by the v2 AHK program <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Issues with VS Code and new setup F5 instead of run arrow<\/h3>\n\n\n\n<p>One thing with VS Code now is you have to use the F5 function key to run the fie, whereas before there was an arrow to the right of the ribbon that I always used, so its something I&#8217;m going to have to get used to. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">V1 to V2 Script Converter<\/h3>\n\n\n\n<p>While looking up info about V1 &amp; V2 AutoHotKey  I came across a forum item on  V1 to V2 Script Converter <strong><a rel=\"noreferrer noopener\" href=\"https:\/\/www.autohotkey.com\/boards\/viewtopic.php?f=6&amp;t=25100&amp;sid=e5af74f28033bbeb9e352338517a2d0f\" target=\"_blank\">here<\/a><\/strong> and also a <strong><a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/mmikeww\/AHK-v2-script-converter\" target=\"_blank\">github repository with the code<\/a><\/strong>. I had to convert extensions from .ahk to .ahk2 and also for any #includes in the code . <\/p>\n\n\n\n<p>I haven&#8217;t tried it yet but it looks interesting and may be a handy way to start learning the different structure. <\/p>\n\n\n\n<p>I have a couple of scripts I use all the time and they would be good learning projects and this could be a good tool to start with. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">End comment<\/h2>\n\n\n\n<p>I&#8217;m pleased to have this working now. I&#8217;m keen to explore version 2 code and also to write in V2 as well. It took a while.<\/p>\n\n\n\n<p>I&#8217;m going to do a video on this as there wasn&#8217;t anything too helpful on the net when I went searching.<\/p>\n\n\n\n<p>You have to use functions in V2 so I&#8217;m going to have to get the hang of that. <\/p>\n\n\n\n<p>Moving forward its better to get on with the new as that will become more common over time here as the legacy stuff will start to fade. <\/p>\n\n\n\n<p>Also you can just compile the scripts so people can just use that and don&#8217;t have to worry about version issues. <\/p>\n\n\n\n<p>Video on the topic :<\/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=\"AHK V1 &amp; V2 &amp; VS Code\" width=\"678\" height=\"381\" data-src=\"https:\/\/www.youtube.com\/embed\/ijts57HyN1o?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>I was watching an AutoHotKey video and Version 2 was mentioned, and the fact that it is not backward compatible with Version 1. It is currently in beta stage and its a zip file so you can install it anywhere. I&#8217;m a bit confused about versioning as the current release (v1) has an L next [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7328,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[466],"tags":[],"class_list":["post-7327","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-autohotkey"],"featured_image_src":"https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/2021-10-02-08_27_54-Add-New-Post-\u2039-Vast-\u2014-WordPress-\u2014-Mozilla-Firefox-600x400.jpg","featured_image_src_square":"https:\/\/max-drake.cc\/wp-content\/uploads\/2021\/10\/2021-10-02-08_27_54-Add-New-Post-\u2039-Vast-\u2014-WordPress-\u2014-Mozilla-Firefox-600x600.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\/7327","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=7327"}],"version-history":[{"count":0,"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/posts\/7327\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/media\/7328"}],"wp:attachment":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}