Skip to content

support AHK version 2.0 and up #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hklene opened this issue Dec 17, 2024 · 16 comments
Open

support AHK version 2.0 and up #77

hklene opened this issue Dec 17, 2024 · 16 comments

Comments

@hklene
Copy link

hklene commented Dec 17, 2024

I updated to recent version 2.0.18 of AHK
https://www.autohotkey.com/download/

and cannot load your VD-Lib anymore:

grafik

@hklene
Copy link
Author

hklene commented Dec 17, 2024

Here is the docs on changes between v1.1 and v2.0:
https://www.autohotkey.com/docs/v2/v2-changes.htm

@FuPeiJiang
Copy link
Owner

@hklene Where should I put the code if AHK v2 is supported ?

@hklene
Copy link
Author

hklene commented Dec 17, 2024

I only stumbled over this today, so haven't put much thought into it. Therefor without trying this first, I share my thoughts:

  1. Maybe some of the syntax changes were anticipated and might be backward-compatible with 1.1? So eventually some code can be written in a way that both interpreters can run the same source? You'll need some robust test-setup to try every change in both versions.
  2. Maybe some constructs could be rewritten/refactored, e.g. if there is an unsolvable incompatibility with a switch-case statement, you might fall back to an if-then-else cascade.
  3. Naively I would expect some way, you can query the AHK version and build a conditional import - at the price of duplicating some code.
  4. Ultimately, you'd have to do the jump, as I expect the old 1.1 version will decline in popularity more and more. For some time you might want to still support it, or at least offer it as an archived download. But as life continues, I suppose, sooner or later you will just do the jump and ask your users, to update as well.

Hope this helps ...

@FuPeiJiang
Copy link
Owner

@hklene I don't think there's conditional import in AHK, supporting both would require omitting statements and directives, and probably more

But here's the v2 branch: https://github.com/FuPeiJiang/VD.ahk/tree/v2_port

@boardtc
Copy link

boardtc commented Jan 27, 2025

Hi. The https://github.com/FuPeiJiang/VD.ahk/blob/v2_port/README.md doesn't explain how to use it. I figured out the include, so in my script I try:

`
#Include VD.ah2 ; Ensure VD.ahk is in the same folder as this script

numpad1::VD.goToDesktopNum(1)
numpad2::VD.goToDesktopNum(2)
numpad3::VD.goToDesktopNum(3)
`

But loading that gives an error from line #1 in vd.ah2:
Error: Functions cannot contain classes. Text: class VD {

Has anyone got this port working?

Any help appreciated.

@FuPeiJiang
Copy link
Owner

@boardtc I think you will only get this error when you have v1 installed and you are trying to run this v2 script, you should add #Requires AutoHotkey v2.0 at the top of your script to see additional hints

@FuPeiJiang
Copy link
Owner

Are you able to run VD examples.ah2 ?
I would right click on it, and "open with", and select a ahkv2 interpreter/exe, wherever it is

@boardtc
Copy link

boardtc commented Jan 27, 2025

@boardtc I think you will only get this error when you have v1 installed and you are trying to run this v2 script

Thanks, @FuPeiJiang. I have ahk & ah2 installed in C:\Program Files\AutoHotkey and C:\Program Files\AutoHotkey\v2 retrospectively.

Are you able to run VD examples.ah2 ? I would right click on it, and "open with", and select a ahkv2 interpreter/exe, wherever it is

If I double-click VD examples.ah2

it opens a modal win titled:
VD.ahk (though it is ah2) examples WinTitle

I can then press numpad2, and this modal moves to the second virtual. I guess that's what you mean by my running!

I tried moving #Requires AutoHotkey v2.0 to the first line and adding

`;#SETUP START
#SingleInstance force
ListLines 0
SendMode "Input"
SetWorkingDir A_ScriptDir
KeyHistory 0
#WinActivateForce

ProcessSetPriority "H"

SetWinDelay -1
SetControlDelay -1

;include the library
#Include %A_LineFile%..\VD.ah2

;#SETUP END`

This is the only include I use. At the bottom of my file, I use:

`
numpad1::VD.goToDesktopNum(1)
numpad2::VD.goToDesktopNum(2)
numpad3::VD.goToDesktopNum(3)

`

I now get the message:

Error: Hotkeys/hotstrings are not allowed inside functions or classes.
Text: numpad1::VD.goToDesktopNum(1)

Can the readme provide a simple example of the minimum to add to one's ah2 file to move windows with a shortcut?

@FuPeiJiang
Copy link
Owner

@boardtc if VD examples.ah2 works, then you can copy the file and start deleting lines from it until you get the "minimum" lines you need, but this below is the minimum that you'd need:

minimum example.ah2:

;#SETUP START
#SingleInstance force
ListLines 0
SendMode "Input"
SetWorkingDir A_ScriptDir
KeyHistory 0
#WinActivateForce

ProcessSetPriority "H"

SetWinDelay -1
SetControlDelay -1

;include the library
#Include %A_LineFile%\..\VD.ah2
;#SETUP END

numpad1::VD.goToDesktopNum(1)
numpad2::VD.goToDesktopNum(2)
numpad3::VD.goToDesktopNum(3)

note the:
#Include %A_LineFile%\..\VD.ah2
vs
#Include %A_LineFile%..\VD.ah2

I don't think it's the autohotkey interpreter version, since VD examples.ah2 works

@boardtc
Copy link

boardtc commented Jan 28, 2025

@FuPeiJiang, thanks for that and for finding my error with the slash; my bad. That's working now.

I am using:

#Requires AutoHotkey v2.0
;#SETUP START
#SingleInstance force
ListLines 0
SendMode "Input"
SetWorkingDir A_ScriptDir
KeyHistory 0
#WinActivateForce

ProcessSetPriority "H"

SetWinDelay -1
SetControlDelay -1

;include the library
#Include %A_LineFile%\..\VD.ah2

;#SETUP END

VD.createUntil(3) ;create until we have at least 3 VD

return

;#useful stuff
numpad1::VD.goToDesktopNum(1)
numpad2::VD.goToDesktopNum(2)
numpad3::VD.goToDesktopNum(3)

;follow your window
numpad4::VD.MoveWindowToDesktopNum("A",1).follow()
numpad5::VD.MoveWindowToDesktopNum("A",2).follow()
numpad6::VD.MoveWindowToDesktopNum("A",3).follow()

;just move window
numpad7::VD.MoveWindowToDesktopNum("A",1)
numpad8::VD.MoveWindowToDesktopNum("A",2)
numpad9::VD.MoveWindowToDesktopNum("A",3)

; wrapping / cycle back to first desktop when at the last
^+#left::VD.goToRelativeDesktopNum(-1)
^+#right::VD.goToRelativeDesktopNum(+1)

; move window to left and follow it
#!left::VD.MoveWindowToRelativeDesktopNum("A", -1).follow()
; move window to right and follow it
#!right::VD.MoveWindowToRelativeDesktopNum("A", 1).follow()

;getters and stuff
f1::Msgbox VD.getCurrentDesktopNum()
f2::Msgbox VD.getCount()
f3::Exitapp

@boardtc
Copy link

boardtc commented Jan 28, 2025

AI summary of above I found useful:

Desktop Management:

  • Numpad1: Go to Desktop 1
  • Numpad2: Go to Desktop 2
  • Numpad3: Go to Desktop 3
  • Numpad4: Move the window to Desktop 1 and follow it
  • Numpad5: Move the window to Desktop 2 and follow it
  • Numpad6: Move the window to Desktop 3 and follow it
  • Numpad7: Move the window to Desktop 1
  • Numpad8: Move the window to Desktop 2
  • Numpad9: Move the window to Desktop 3
  • Ctrl + Shift + Win + Left Arrow: Move to the previous desktop
  • Ctrl + Shift + Win + Right Arrow: Move to the next desktop

Window Management:

  • Alt + Win + Left Arrow: Move the window to the left desktop and follow it
  • Alt + Win + Right Arrow: Move the window to the right desktop and follow it

Getters:

  • F1: Show the current desktop number
  • F2: Show the total number of desktops

Exit:

  • F3: Exit the script

@boardtc
Copy link

boardtc commented Jan 28, 2025

Note that numpad5 gives the error:

Error: Target window not found.

Specifically: ahk_id 266236

---- G:\My Drive\ahk\VD.ah2
554: {
555: VD.goToDesktopNum(this.desktopNum, false)

▶ 556: WinActivate("ahk_id " this.hwnd)
557: }
559: {

@FuPeiJiang
Copy link
Owner

@boardtc I've made "Target window not found" fail silently, this happened for me when the VD failed to switch
I can't reliably get the VD to fail to switch, does it happen almost randomly for you ?

@boardtc
Copy link

boardtc commented Jan 28, 2025

Thanks for your help again. I'll test again if possible. Right now, even though I've restarted my script a bunch of times, hitting the numpad keys types the number rather than moving the window 😭 I can't see what's changed (numlock is on), not the script anyway, which shows last changed 90 minutes ago.,

@boardtc
Copy link

boardtc commented Jan 30, 2025

I have no idea what changed, but the above script (#77 (comment)) is no longer working. Numpad leys are no longer intercepted, and I've run out of debugging ideas...

@FuPeiJiang
Copy link
Owner

@boardtc does VD examples.ah2 work ?
If not, does a simple script work ?
A script with nothing inside but:

F1::MsgBox 1
Numpad1::MsgBox 11

If not, then check if your Antivirus (if any), is silently blocking autohotkey

If anything works, then add stuff or remove stuff from it until you get what you want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants