I'm migrating my code from v1 to v2 (and its a very painful process even though I'm using the convertor by mmikeww on github). I still want to use some scripts which I did not make and have no idea whether it will still exactly as intended after putting it though the convertor so I haven't deleted v1. I downloaded the v2 setup, set v2 up, created a script, tried to compile it, got a lot of errors about basically every line, realized that the compiler is still on v1.1.36 for some reason, tried to google(used the forums more than google), found no simple solutions, gave up on v2 for a while. Is there any way to use v1 compiler and v2 compiler on the same machine without going into file extension, registry and all that? I am using vscode if that has anything to do with this.
Also is there a good vscode extension that works for both v1 and v2?
Running v1 and v2 Scripts on the same device
Re: Running v1 and v2 Scripts on the same device
hi. GameNtt
I can think of a code before each script where you rename the .exe file to Autohotkey__1.exe version 1, while at the same time renaming the existing Autohotkey_2.exe to AutoHotkey.exe; and vice versa when using version 1. In order not to conflict with the system (and have to use administrator privileges, AutoHotkey would have to be installed in a non-system directory or drive.
I can think of a code before each script where you rename the .exe file to Autohotkey__1.exe version 1, while at the same time renaming the existing Autohotkey_2.exe to AutoHotkey.exe; and vice versa when using version 1. In order not to conflict with the system (and have to use administrator privileges, AutoHotkey would have to be installed in a non-system directory or drive.
Re: Running v1 and v2 Scripts on the same device
Nothing special is required. Installing v2 leaves v1 intact. AutoHotkey can then detect whether a script is coded in v1 or v2, and use the corresponding interpreter. There is also a #Requires directive.
Explained: Installation
Explained: Installation
Last edited by mikeyww on 29 Dec 2022, 08:06, edited 2 times in total.
Re: Running v1 and v2 Scripts on the same device
Oh great.mikeyww wrote: ↑29 Dec 2022, 08:00Nothing special is required. Installing v2 leaves v1 intact. AutoHotkey can then detect whether a script is coded in v1 or v2, and use the corresponding interpreter. There is also a #Requires directive.
Explained: #Requires[/c]]Installation
![Thumbup :thumbup:](./images/smilies/icon_thumbup.gif)
I think I tried it in a beta version and it didn't have that capability yet. I may be wrong.
Re: Running v1 and v2 Scripts on the same device
I find that the following configuration works well.
Re: Running v1 and v2 Scripts on the same device
mikeyww. What is that window called? or is it when installing.
Re: Running v1 and v2 Scripts on the same device
I believe that it runs with the installer, but it can be run again. On my system: c:\Program Files\AutoHotkey\UX\ui-launcherconfig.ahk
Re: Running v1 and v2 Scripts on the same device
C:\Users\GameNtt\Desktop\Copy of v1 Scripts\RndmStf_v2new.ahk (2) : ==> This script requires AutoHotkey v2.0.
Current interpreter: AutoHotkey v1.1.36.02 Unicode 64-bit
C:\Program Files\AutoHotkey\AutoHotkeyU64.exe
Hmmm.
Current interpreter: AutoHotkey v1.1.36.02 Unicode 64-bit
C:\Program Files\AutoHotkey\AutoHotkeyU64.exe
Hmmm.
Re: Running v1 and v2 Scripts on the same device
Thank you mikeyww. Yes, the file is there.
Re: Running v1 and v2 Scripts on the same device
https://imgur.com/qy8DN8u
In v2 all the v2 applications are there. 32, UIA32, 64, UIA64
In v2 all the v2 applications are there. 32, UIA32, 64, UIA64
Re: Running v1 and v2 Scripts on the same device
If you get an error message about the script requiring the other version, it usually means that you need to adjust some of the syntax in the script, because there is a bug or because the script needs to clarify which version it uses.
Re: Running v1 and v2 Scripts on the same device
The very first line of the v2 script is
#Requires AutoHotkey v2.0.0
#Requires AutoHotkey v2.0.0
Re: Running v1 and v2 Scripts on the same device
And what are all of the lines that come after that?
Re: Running v1 and v2 Scripts on the same device
Code: Select all
#Requires AutoHotkey v2.0.0
#SingleInstance Force
OutputDebug A_AhkVersion
Re: Running v1 and v2 Scripts on the same device
I ran the script that you have posted here. As expected, it immediately exited, and with no warnings or errors.
I recommend that when people have a problem with a script, they should post some version of the script that the reader can run to demonstrate the problem.
I recommend that when people have a problem with a script, they should post some version of the script that the reader can run to demonstrate the problem.
Re: Running v1 and v2 Scripts on the same device
mikeyww wrote: ↑29 Dec 2022, 12:07I ran the script that you have posted here. As expected, it immediately exited, and with no warnings or errors.
I recommend that when people have a problem with a script, they should post some version of the script that the reader can run to demonstrate the problem.
Code: Select all
#Requires AutoHotkey v2.0.0
#SingleInstance
OutputDebug A_AhkVersion
/*
SendMode "Input"
SetWorkingDir A_ScriptDir
;#Include "Cursor Schemes.ahk"
CoordMode "Mouse", "Screen"
SetTitleMatchMode(2)
GroupAdd("Gui_Blank", "ahk_class AutoHotkeyGUI")
GroupAdd("Gui_Blank", "BlankScr.ahk")
global m := 1
mvmouse(m)
OutputDebug(mod(m,2))
global scrbrt := GetBrightness()
global scrbrt2 := GetBrightness()
#+!s::Suspend()
#^!+s::SoundBeep()
#!+e::Edit()
#!+r::Reload()
#!+q::Run("C:\Program Files\AutoHotkey\WindowSpy.ahk")
#!+f::Run("C:\Program Files\Everything\Everything.exe")
#^!c::SystemCursor("Toggle")
#!+c::MouseMove(683, 359)
^!+w::Send("web.archive.org/web/*/")
;!+6::MouseMove,840,480
>+^a::Send("awesome")
>+Up::MouseMove(0, -1, 0, "R")
>+Down::MouseMove(0, 1, 0, "R")
>+Left::MouseMove(-1, 0, 0, "R")
>+Right::MouseMove(1, 0, 0, "R")
^F1::SetDefaultKeyboardLang(0x4009) ; english
^F2::SetDefaultKeyboardLang(0x0408) ; greek
^F3::SetDefaultKeyboardLang(0x0411) ; japanese
^F4::SetDefaultKeyboardLang(0x0419) ; russian
#c::Run("Calc.exe")
#!k::Run("D:\KaiZen-1.0.0\KaiZen\KaiZen.exe")
^!b::Run("C:\Program Files\BlueJ\BlueJ.exe")
#^!g::Run("C:\Users\GameNtt\Desktop\GammaAdj.ahk")
#!+m::MsgBox(m, "", "T3")
#+!d::Run("C:\Users\GameNtt\Desktop\DayofanyDate.ahk")
#+s::Send("System.out.println(`"`");{Left 3}")
#+p::Send("^a import java.util.*; {Enter} public class placeholder{Enter} {{} {Enter} public static void main(String args[]){Enter}{{}{Enter}Scanner sc = new Scanner(System.in);{Enter}System.out.println(`"`");{Enter}{}}{Enter}{}} ^+i")
^!+i::
{ ; V1toV2: Added bracket
ChangeCursorScheme("Windows Inverted")
SoundBeep()
return
} ; V1toV2: Added Bracket before hotkey or Hotstring
#!+w::
{ ; V1toV2: Added bracket
path := WinGetProcessPath("A")
MsgBox(path)
return
} ; V1toV2: Added Bracket before hotkey or Hotstring
#!s::
{ ; V1toV2: Added bracket
Click("1300, 350")
Send("^a")
Send("10 {Enter}")
Send("{Esc 2}")
Send("{Up}")
Send("^{Right}")
Send("{Down}")
return
} ; V1toV2: Added Bracket before hotkey or Hotstring
#!w::
{ ; V1toV2: Added bracket
Click("1300, 375")
Send("^a")
Send("10 {Enter}")
Click("1300, 400")
Send("^a")
Send("270 {Enter}")
Send("{Esc 2}")
Send("{Up}")
Send("^{Right}")
Send("{Down}")
return
} ; V1toV2: Added Bracket before hotkey or Hotstring
#+z::
{ ; V1toV2: Added bracket
Send("n")
Send("^a")
Send("{Left}")
Send("+{Right 4}")
Send("{Space}")
Send("{Backspace}")
Send("{Right 4}")
Send("-")
Send("{Right 2}")
Send("-")
Send("{Right 2}")
Send("+{Right}")
Send("{Space}")
Send("{Right 2}")
Send(".")
Send("{Right 2}")
Send(".")
Send("{Enter}")
return
} ; V1toV2: Added Bracket before hotkey or Hotstring
#!q::
{ ; V1toV2: Added bracket
Send("{Down 10}")
Send("{Home}")
Send("{Right}")
return
} ; V1toV2: Added Bracket before hotkey or Hotstring
>+`::
{ ; V1toV2: Added bracket
wid := ""
hei := ""
title := ""
x := ""
y := ""
title := WinGetTitle("A")
WinGetPos(&x, &y, &wid, &hei, "A")
MsgBox("WinHeight = " hei ", WinWidth = " wid)
return
} ; V1toV2: Added Bracket before hotkey or Hotstring
!^9::
{ ; V1toV2: Added bracket
m++
mvmouse(m)
OutputDebug("m = " m)
return
} ; V1toV2: Added Bracket before hotkey or Hotstring
^F12::
{ ; V1toV2: Added bracket
Run("C:\Users\GameNtt\Desktop\BlankScr.ahk")
SystemCursor("Off")
scrbrt3 := GetBrightness()
scrbrt4 := GetBrightness()
SoundBeep()
mvmouse(0)
SetBrightness(0)
;OutputDebug, Screen Brightness before changing is %scrbrt3%
OutputDebug("Entering psuedo-power off")
WinWaitActive("ahk_group Gui_Blank")
SoundBeep()
WinWaitNotActive("ahk_group Gui_Blank")
SoundBeep()
mvmouse(m)
SystemCursor("On")
scrbrt3 := GetBrightness()
;OutputDebug, Screen Brightness on changing is %scrbrt3%
SetBrightness(scrbrt4)
scrbrt3 := GetBrightness()
OutputDebug("Exiting psuedo-power off")
;OutputDebug, Screen Brightness after changing %scrbrt3%
return
} ; V1toV2: Added Bracket before hotkey or Hotstring
!,::
{ ; V1toV2: Added bracket
AdjustScreenBrightness(-10)
Sleep(100)
scrbrt2 := GetBrightness()
OutputDebug("Current Screen Brightness in `" is "scrbrt2")
Return
} ; V1toV2: Added Bracket before hotkey or Hotstring
!.::
{ ; V1toV2: Added bracket
AdjustScreenBrightness(10)
Sleep(100)
scrbrt2 := GetBrightness()
OutputDebug("Current Screen Brightness in `" is "scrbrt2")
Return
} ; V1toV2: Added Bracket before hotkey or Hotstring
^+x::
{ ; V1toV2: Added bracket
OutputDebug(A_AhkVersion)
Return
} ; Added bracket before function
GetBrightness()
{
Return ComObjGet("winmgmts:\root\WMI").InstancesOf("WmiMonitorBrightness WHERE Active=TRUE").ItemIndex(0).CurrentBrightness
}
SetBrightness(val)
{
service := "winmgmts:{impersonationLevel=impersonate}!\\.\root\WMI"
monitors := ComObjGet(service).ExecQuery("SELECT * FROM WmiMonitorBrightness WHERE Active=TRUE")
monMethods := ComObjGet(service).ExecQuery("SELECT * FROM wmiMonitorBrightNessMethods WHERE Active=TRUE")
minBrightness := 0 ; level below this is identical to this
if (val < minBrightness) ; parenthesis is necessary here
val := minBrightness
toSet := val
if (toSet > 100)
return
if (toSet < minBrightness)
toSet := minBrightness
for i in monMethods {
i.WmiSetBrightness(1, toSet)
break
}
}
AdjustScreenBrightness(step)
{
service := "winmgmts:{impersonationLevel=impersonate}!\\.\root\WMI"
monitors := ComObjGet(service).ExecQuery("SELECT * FROM WmiMonitorBrightness WHERE Active=TRUE")
monMethods := ComObjGet(service).ExecQuery("SELECT * FROM wmiMonitorBrightNessMethods WHERE Active=TRUE")
minBrightness := 5 ; level below this is identical to this
for i in monitors {
curt := i.CurrentBrightness
break
}
if (curt < minBrightness) ; parenthesis is necessary here
curt := minBrightness
toSet := curt + step
if (toSet > 100)
return
if (toSet < minBrightness)
toSet := minBrightness
for i in monMethods {
i.WmiSetBrightness(1, toSet)
break
}
}
SystemCursor(OnOff:=1) ; INIT = "I","Init"; OFF = 0,"Off"; TOGGLE = -1,"T","Toggle"; ON = others
{
static AndMask, XorMask, $, h_cursor ,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 , b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13 , h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13
if (OnOff = "Init" or OnOff = "I" or $ = "") ; init when requested or at first call
{
$ := "h" ; active default cursors
h_cursor := Buffer(4444, 1) ; V1toV2: if 'h_cursor' is a UTF-16 string, use 'VarSetStrCapacity(&h_cursor, 4444)'
AndMask := Buffer(32*4, 0xFF) ; V1toV2: if 'AndMask' is a UTF-16 string, use 'VarSetStrCapacity(&AndMask, 32*4)'
XorMask := Buffer(32*4, 0) ; V1toV2: if 'XorMask' is a UTF-16 string, use 'VarSetStrCapacity(&XorMask, 32*4)'
system_cursors := "32512,32513,32514,32515,32516,32642,32643,32644,32645,32646,32648,32649,32650"
c := StrSplit(system_cursors,",")
Loop c.Length
{
h_cursor := DllCall("LoadCursor", "Ptr", 0, "Ptr", c[A_Index])
h%A_Index% := DllCall("CopyImage", "Ptr", h_cursor, "UInt", 2, "Int", 0, "Int", 0, "UInt", 0)
b%A_Index% := DllCall("CreateCursor", "Ptr", 0, "Int", 0, "Int", 0, "Int", 32, "Int", 32, "Ptr", AndMask, "Ptr", XorMask)
}
}
if (OnOff = 0 or OnOff = "Off" or $ = "h" and (OnOff < 0 or OnOff = "Toggle" or OnOff = "T"))
$ := "b" ; use blank cursors
else
$ := "h" ; use the saved cursors
Loop c.Length
{
h_cursor := DllCall("CopyImage", "Ptr", %$%%A_Index%, "UInt", 2, "Int", 0, "Int", 0, "UInt", 0)
DllCall("SetSystemCursor", "Ptr", h_cursor, "UInt", c[A_Index])
}
}
mvmouse(val)
{
global valm := mod(val, 2)
if(valm = 0)
{
SetTimer(MoveMouse,0)
OutputDebug "Switched on"
{ ; V1toV2: Added bracket
If ( A_TimeIdle > 59000 && A_TimeIdle < 60001)
{
MouseMove(1, 0, , "R")
MouseMove(-1, 0, , "R")
time := FormatTime(, "HH:mm:ss")
OutputDebug("Moved at time " time " and the value of valm is " valm)
}
return
}
Else
{
SetTimer(MoveMouse,0)
OutputDebug("Switched off")
}
Return
}
} ; V1toV2: Added bracket before function
SetDefaultKeyboardLang(LocaleID)
{
Static SPI_SETDEFAULTINPUTLANG := 0x005A, SPIF_SENDWININICHANGE := 2
Lan := DllCall("LoadKeyboardLayout", "Str", Format("{:08x}", LocaleID), "Int", 0)
binaryLocaleID := Buffer(4, 0) ; V1toV2: if 'binaryLocaleID' is a UTF-16 string, use 'VarSetStrCapacity(&binaryLocaleID, 4)'
NumPut("UPtr", LocaleID, binaryLocaleID)
DllCall("SystemParametersInfo", "UInt", SPI_SETDEFAULTINPUTLANG, "UInt", 0, "UPtr", binaryLocaleID, "UInt", SPIF_SENDWININICHANGE)
owindows := WinGetList(,,,)
awindows := Array()
windows := owindows.Length
For v in owindows
{ awindows.Push(v)
}
Loop awindows.Length {
PostMessage(0x50, 0, Lan, , "ahk_id " awindows[A_Index])
}
}
cMod(dividend, divisor)
{
if(dividend > 0)
{
Return Mod(dividend, divisor)
}
else if(divident < 0)
{
While(dividend < 0)
{
dividend += divisor
}
return Mod(dividend, divisor)
}
else
{
Return 0
}
}
*/
Re: Running v1 and v2 Scripts on the same device
I ran the exact script that you posted and saw no errors or warnings.
If you are going to post working scripts, then you might not need the help forum!
If you are going to post working scripts, then you might not need the help forum!
Re: Running v1 and v2 Scripts on the same device
I tell you, the exact error showing up is this
C:\Users\GameNtt\Desktop\Copy of v1 Scripts\RndmStf_v2new.ahk (2) : ==> This script requires AutoHotkey v2.0.
Current interpreter: AutoHotkey v1.1.36.02 Unicode 64-bit
C:\Program Files\AutoHotkey\AutoHotkeyU64.exe
I don't know why, I don't know how, but that is happening. And about your computer running with no problem, that could be the case. Mine isn't recognizing any of the ahk v2 applications.
Oh yeah, and one more thing : when I go into the v2 folder and click on any one of the applications, it says that this .ahk file/script doesn't exist.
I even redownloaded and reexecuted the setup, it did not work.
C:\Users\GameNtt\Desktop\Copy of v1 Scripts\RndmStf_v2new.ahk (2) : ==> This script requires AutoHotkey v2.0.
Current interpreter: AutoHotkey v1.1.36.02 Unicode 64-bit
C:\Program Files\AutoHotkey\AutoHotkeyU64.exe
I don't know why, I don't know how, but that is happening. And about your computer running with no problem, that could be the case. Mine isn't recognizing any of the ahk v2 applications.
Oh yeah, and one more thing : when I go into the v2 folder and click on any one of the applications, it says that this .ahk file/script doesn't exist.
I even redownloaded and reexecuted the setup, it did not work.
Re: Running v1 and v2 Scripts on the same device
Hmm. Sounds like some kind of installation issue. I would recommend uninstalling all of your AHK versions, then installing v1, and then installing v2, using the standard installers and options. You can then run a simple test script.
Code: Select all
MsgBox 'Test'
Re: Running v1 and v2 Scripts on the same device
@GameNtt
In your first post you expressed concern that Ahk2Exe v1.1.36.02 was being used to compile v2 scripts. However this is completely normal as the same compiler is used for both v1 and v2 scripts. The compiler knows which version is being compiled by noting the version of the Base file that has been selected by the user. If it is a v2 Base file, then Ahk2Exe will do a version 2 compile.
Cheers
In your first post you expressed concern that Ahk2Exe v1.1.36.02 was being used to compile v2 scripts. However this is completely normal as the same compiler is used for both v1 and v2 scripts. The compiler knows which version is being compiled by noting the version of the Base file that has been selected by the user. If it is a v2 Base file, then Ahk2Exe will do a version 2 compile.
Cheers
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
Who is online
Users browsing this forum: macromint and 97 guests