Can I run AHK v1 and v2 Simultaneously on Same Device?

Discuss the future of the AutoHotkey language
User avatar
Tigerlily
Posts: 352
Joined: 04 Oct 2018, 22:31

Can I run AHK v1 and v2 Simultaneously on Same Device?

27 Mar 2019, 05:51

I want to start writing and creating in v2, however much code I've written for work is done in v1 and I don't have the time to go back and convert to v2 for the foreseeable future.

I often have to maintain these scripts to add/remove features and functionality, probably once or twice a month.


Can I have AHK v2 installed and still run AHK v1 scripts with the v1 interpretter AND run AHK v2 scripts with the v2 interpretter? Not sure if I'm using the right verbiage, but I think you'll get what I'm trying to say.

This issue is the main reason I'm skeptical to start coding in v2.


If the solution to this isn't something that is easy to set up, I'm open to your solution!

If it is something that is a massive difficulty/time undertaking, then save your time and don't share that solution ;)


Much appreciated, your time and knowledge :beer:
-TL
User avatar
SALZKARTOFFEEEL
Posts: 89
Joined: 10 May 2017, 11:14
GitHub: SALZKARTOFFEEEL
Location: Germany
Contact:

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

27 Mar 2019, 06:37

This is possible and – at its core – doesn't require any setup.
AHK v2 doesn't come with an installer as v1 does, you just copy the contents of the ZIP-file you download somewhere and that's the installation process. As a result, after ‘installing’ v2, all scripts you launch will still run with the v2 interpreter. You have to make some registry tweaks to make it work properly.
I have made some more tweaks, so that I can happily run v2 and v1 code simultaneously!
When I right-click a .ahk file, this is what my context menu looks like:
Image
Everything in the main menu is v2, while everything under “Legacy Syntax” is v1.
If you are interested, I can prepare a file that you run, which automatically updates the Registry to this state, so that you can have it like this as well.

Another solution is to simply associate .ahk2 files with v2, and all regular .ahk files with v1. This requires a different Registry modification, but is actually much easier.
Here too, hit me up if you are interested!
User avatar
JoeWinograd
Posts: 1590
Joined: 10 Feb 2014, 20:00

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

27 Mar 2019, 14:14

Hi Tigerlily,

I'm using V1 and V2 on the same system and wanted to pass along a suggestion to you, which is...don't use ahk2 as the file type. The first thing I tried was ahkv2...had a problem. Next thing I tried was ahk2...had the same problem. I posted this question on it:

https://autohotkey.com/boards/viewtopic.php?f=5&t=53788

Then this bug report on it:

https://autohotkey.com/boards/viewtopic.php?f=14&t=53840

As you can see from the replies by lexikos, he figured out that the problem is due to the 8.3 short file name. I changed my AHK V2 file type to ah2 and haven't had a problem since. Regards, Joe
User avatar
SALZKARTOFFEEEL
Posts: 89
Joined: 10 May 2017, 11:14
GitHub: SALZKARTOFFEEEL
Location: Germany
Contact:

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

27 Mar 2019, 15:47

This is good to know. Then I made the right choice with not going for the separate file extension. (Although I don't use the Task Scheduler myself.)
User avatar
JoeWinograd
Posts: 1590
Joined: 10 Feb 2014, 20:00

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

27 Mar 2019, 16:12

> I made the right choice with not going for the separate file extension.

Sounds like "the right choice" for you, but there are obviously plusses and minuses, so the right choice is going to vary by individual. I like to run AHK scripts via a double-click in my file manager and via just a file name in the Program/script field of the Task Scheduler, both of which I use heavily. So, the right choice for me is definitely a different (3-character) file extension. But your registry tweak is very clever and may be the right choice for other folks. Regards, Joe
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

27 Mar 2019, 16:20

- You can set the AHK file association to open with an AHK exe and a script, the script can check the file contents/path, and open with AHK v1 or v2 accordingly.
- Another plan is to backport features to AHK v1, such that you can run all of your scripts in AHK v1, and gradually update your scripts until you're ready to move to AHK v2.
- The very few features we need to backport:
[Loop (expression), LoopXXX, #If WinActive() (optimised)]
Is AHK dead? (not developed any more) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=17&t=62505&p=266650#p266650
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
guest3456
Posts: 3134
Joined: 09 Oct 2013, 10:31

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

27 Mar 2019, 18:32

i just download the v2 zip, and then then i want to run a v2 script, i just drag and drop it onto the v2 exe

User avatar
Tigerlily
Posts: 352
Joined: 04 Oct 2018, 22:31

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

30 Mar 2019, 05:30

Thank you all very much for your informative replies. Definitely helping motivate me to start creating in v2 and H_v2. I'm really excited :D Just downloaded _H v2 and v2 :)

For starters, I am going to start with guest3456's simply drag and drop. Then as I get more comfortable, I may use SALZ's neato registry hack.. Then possibly create my own unique solution that fits me best @Joe_W (thanks for the filename extension heads up!)

Now on to v2 editors. What do y'all use for v2? Anything specific for _H v2? I usually use SciTE but just installed AHK Studio.


Okay.. so after writing this I found AHK-EXE-Swapper by Evil C. I haven't used it much yet, but looks awesome and y'all may want to think of using it (if not already) to dynamically switch between AHK versions - nnnik recommended it to me.

GitHub: https://github.com/ahkscript/AHK-EXE-Swapper
Forum post: https://github.com/ahkscript/AHK-EXE-Swapper

Thanks again! :monkeysay: :xmas:
-TL
User avatar
SALZKARTOFFEEEL
Posts: 89
Joined: 10 May 2017, 11:14
GitHub: SALZKARTOFFEEEL
Location: Germany
Contact:

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

30 Mar 2019, 08:57

As an editor I use Sublime Text. It does not support AHK syntax out of the box, so I have created my own syntax highlighter for v2 quite some time ago. It is not perfect and I really need to update it.
User avatar
Tigerlily
Posts: 352
Joined: 04 Oct 2018, 22:31

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

01 Apr 2019, 00:39

SALZKARTOFFEEEL wrote:
30 Mar 2019, 08:57
As an editor I use Sublime Text. It does not support AHK syntax out of the box, so I have created my own syntax highlighter for v2 quite some time ago. It is not perfect and I really need to update it.
Wow that is nice to look at - very stripped down and organized :thumbup:

;) Interesting you bring this up because I was just talking with maestrith about going ahead and creating an up to date AHK Studio v2 syntax file. It will be in XML, since that is what AHK Studio is in and it will be very basic structure:

Name, ( Parameters [ Optional Parameters ] )
Brief Description

If you're interested, I can let you know when it is finalized and maybe you could easily transfer the same up-to-date data into your own custom format for Sublime. It will likely take me at least a month or two though since I'm busy with other things and am still quite new at this :)


By the way - update on the AHK-EXE SWAPPER by EvilC:

Appears to be working flawlessly - you can back up any version (afaik) by dropping a zip file of any AHK v# into one of the folders it comes with that stores it. Then switch easily back and forth in seconds between backed up versions with two to three clicks. I like it.


What would be even better though would be if :

Interpreter scans file - uh oh LINE ERROR at line 1!! what?! v2 has no idea what #SingleInstance, Force is anymore! well lets just go through the same process that EvilC's mechanism does but in a more dynamic way, in a previously decided order.

---------------------------
1337 KEY CUTZ.ahk
---------------------------
Error at line 1.

Line Text: #SingleInstance, force
Error: This line does not contain a recognized action.

The program will exit.
---------------------------
OK
---------------------------



1. Error when using v2 interpreter on file
2. Recalibrate system and now use latest version of v1 interpreter on file - oh shit that didn't work either? well then your script may sucks :p

I think many scripts will throw an error fairly soon after reading the file anyways .. I'd be willing to risk the possible time wastings.

And same thing, but vice versa, from v1 to v2.. and maybe, since I'm using AHK_H now, it could support 3 options..

hmm
-TL
User avatar
SALZKARTOFFEEEL
Posts: 89
Joined: 10 May 2017, 11:14
GitHub: SALZKARTOFFEEEL
Location: Germany
Contact:

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

01 Apr 2019, 04:02

Tigerlily wrote:
01 Apr 2019, 00:39
;) Interesting you bring this up because I was just talking with maestrith about going ahead and creating an up to date AHK Studio v2 syntax file. It will be in XML, since that is what AHK Studio is in and it will be very basic structure:

Name, ( Parameters [ Optional Parameters ] )
Brief Description

If you're interested, I can let you know when it is finalized and maybe you could easily transfer the same up-to-date data into your own custom format for Sublime. It will likely take me at least a month or two though since I'm busy with other things and am still quite new at this :)
Yeah, please do let me know. I have used AHK Studio in the past but had to switch because it lacked the v2 integration. If this is going to happen, I would probably give it another chance!

I'm not sure how advanced Studio's highlighting engine is, though. If it does not do context-sensitive highlighting, it might not be enough for me.
What I mean with context-sensitive highlighting is the following:
For example: If if you have put an invalid hotkey in your script (like abc::) and you are using my syntax highlighter, you will immediately see that it in invalid.
I really want this kind of a thing and I'm not sure Studio supports that. If it does – great!
User avatar
Tigerlily
Posts: 352
Joined: 04 Oct 2018, 22:31

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

01 Apr 2019, 13:59

SALZKARTOFFEEEL wrote:
01 Apr 2019, 04:02
Tigerlily wrote:
01 Apr 2019, 00:39
;) Interesting you bring this up because I was just talking with maestrith about going ahead and creating an up to date AHK Studio v2 syntax file. It will be in XML, since that is what AHK Studio is in and it will be very basic structure:

Name, ( Parameters [ Optional Parameters ] )
Brief Description

If you're interested, I can let you know when it is finalized and maybe you could easily transfer the same up-to-date data into your own custom format for Sublime. It will likely take me at least a month or two though since I'm busy with other things and am still quite new at this :)
Yeah, please do let me know. I have used AHK Studio in the past but had to switch because it lacked the v2 integration. If this is going to happen, I would probably give it another chance!

I'm not sure how advanced Studio's highlighting engine is, though. If it does not do context-sensitive highlighting, it might not be enough for me.
What I mean with context-sensitive highlighting is the following:
For example: If if you have put an invalid hotkey in your script (like abc::) and you are using my syntax highlighter, you will immediately see that it in invalid.
I really want this kind of a thing and I'm not sure Studio supports that. If it does – great!
I don't beleive that Studio does what you speak of, however I've only used it for a few days now. maestrith actually gave me a personal 1-on-1 tour of Studio, and I must say - IT IS A BEAST. In a good way. I felt very lucky to get such a tour, unfortunately my time was limited so we could not explore the multitudes of other awesome features caked in. There are and endless amount of customization and special features buried in there from ~15 years of development. I bet that could be built in to the "unofficial v2 release". It's not my baby though, so I'll ask about it and see if that's something maestrith would be into.

I'm not exactly sure what you mean by invalid hotkey though? do you mean to say that it is duplicate, or that if executed it would fail? or perhaps both? I have been pondering on this idea of how it would be nice to see if portions of code will execute fully or fail without reloading and reactivating the .ahk file. I knwo there are probably some debug features in editors that do similar to this - but i just want to highlight the code and press #+r and see what happens. Probably a whole lot more complicated to implement in reality than it sounds though.

I'd love to test out your sublime syntax highlighter some time once I'm ready to test out Sublime editor (haven't even attempted to yet). It sounds neat.
-TL
Marrsstar4
Posts: 2
Joined: 10 Apr 2020, 20:06

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

28 Jun 2020, 09:14

Hello SALZKARTOFFEEEL, I know it's kind of later, but i'm looking for something like your registry assocation file as in your post

Posts: 89
Joined: 10 May 2017
GitHub: SALZKARTOFFEEEL
Location: Germany

for compiling both ver. of AHK
any help would be helpful

Greg
User avatar
vvhitevvizard
Posts: 405
Joined: 25 Nov 2018, 10:15
Location: Russia

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

28 Jun 2020, 12:14

A minute ago I've just shared my experience of having multiple AHK interpreter versions side by side in another topic:
https://www.autohotkey.com/boards/viewtopic.php?f=37&t=74971
User avatar
boiler
Posts: 5905
Joined: 21 Dec 2014, 02:44

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

28 Jun 2020, 12:37

Some here might find a script I made useful. With a single click, it runs your script using an alternate AHK binary file, so you can easily run scripts in v2 and leave the v1 installation in place (or vice-versa). No alternate file extensions needed. No swapping binaries needed.
Run Alt AHK Version (RAAV) - written in v1
Run Alt AHK Version (RAAV) - written in v2
User avatar
TheArkive
Posts: 330
Joined: 05 Aug 2016, 08:06
GitHub: TheArkive

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

28 Jun 2020, 16:01

If you want to run many versions of AHK side-by-side, and be able to quickly switch the primary version installed on the system, my AHK Portable Installer will do the trick.
Marrsstar4
Posts: 2
Joined: 10 Apr 2020, 20:06

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

28 Jun 2020, 16:39

Thanks you guys, this will keep me busy for awhile, as I need to get a handle on my versions, I'm trying to re-write a V2 of a V1 and my AHK directories are worst then my garage, totally a mess.
User avatar
nnnik
Posts: 4470
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

29 Jun 2020, 01:57

I use AHK EXE SWAPPER. A tool that switches between several versions of AHK. Not only v1 and v2 but several versions of v1 and v2 too.
Recommends AHK Studio
Unreal_Ed
Posts: 1
Joined: 19 Jul 2020, 23:45

Re: Can I run AHK v1 and v2 Simultaneously on Same Device?

19 Jul 2020, 23:54

SALZKARTOFFEEEL wrote:
27 Mar 2019, 06:37
I have made some more tweaks, so that I can happily run v2 and v1 code simultaneously!
When I right-click a .ahk file, this is what my context menu looks like: [...]

If you are interested, I can prepare a file that you run, which automatically updates the Registry to this state, so that you can have it like this as well.
SALZKARTOFFEEEL, I would really love to have that file that sets up the registry changes because those seem really useful!

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 3 guests