[FEAT]: Use Autohotkey v2 by default #171

Closed
opened 2026-01-05 14:48:42 +01:00 by adam · 18 comments
Owner

Originally created by @sitiom on GitHub (Dec 22, 2022).

Is your feature request related to a problem? Please describe.
Since Autohotkey v2 has reached stable, it might be a good time to migrate completely to v2.

Describe the solution you'd like

Make komorebi use AutoHotkey v2 by default. To do that:

  • Migrate the sample config, helper library, and ahk-asc to v2
  • Generate v2 syntax by default. For compatibility with v1, add a flag in the ahk-library and ahk-asc commands to generate v1 syntax instead.
  • Merge $Env:KOMOREBI_AHK_V1_EXE and $Env:KOMOREBI_AHK_V2_EXE to a single $Env:KOMOREBI_AHK_EXE (either v1 or v2).
  • Remove .ahk2 and just have a single komorebi.ahk file (either v1 or v2). Autohotkey v2 has a launcher script where it can detect the version of the running script and run the appropriate interpreter for it.
    image
    The behavior can be configured in the settings:
    image
    It would be good for komorebi to make use of it.

Describe alternatives you've considered
None.

Additional context
Related to #10

Originally created by @sitiom on GitHub (Dec 22, 2022). **Is your feature request related to a problem? Please describe.** Since Autohotkey v2 [has reached stable](https://github.com/AutoHotkey/AutoHotkey/releases/tag/v2.0.0), it might be a good time to migrate completely to v2. **Describe the solution you'd like** Make komorebi use AutoHotkey v2 by default. To do that: - Migrate the sample config, helper library, and `ahk-asc` to v2 - Generate v2 syntax by default. For compatibility with v1, add a flag in the `ahk-library` and `ahk-asc` commands to generate v1 syntax instead. - Merge `$Env:KOMOREBI_AHK_V1_EXE` and `$Env:KOMOREBI_AHK_V2_EXE` to a single `$Env:KOMOREBI_AHK_EXE` (either v1 or v2). - Remove `.ahk2` and just have a single `komorebi.ahk` file (either v1 or v2). Autohotkey v2 has a [launcher](https://www.autohotkey.com/docs/v2/Program.htm#launcher-cmd) [script](https://www.autohotkey.com/docs/v2/Program.htm#launcher) where it can detect the version of the running script and run the appropriate interpreter for it. ![image](https://user-images.githubusercontent.com/56180050/209056149-9e1adbbd-a3ef-43d7-bb78-350ae63b0327.png) The behavior can be configured in the settings: ![image](https://user-images.githubusercontent.com/56180050/209055066-393cc118-531e-450b-9d32-609536b807aa.png) It would be good for komorebi to make use of it. **Describe alternatives you've considered** None. **Additional context** Related to #10
adam added the enhancement label 2026-01-05 14:48:42 +01:00
adam closed this issue 2026-01-05 14:48:42 +01:00
Author
Owner

@LGUG2Z commented on GitHub (Jan 2, 2023):

There are some significant changes in AHK2 syntax which require commands to Run and RunWait to be surrounded by single (or maybe double?) quotes. Unfortunately I have been unable to find a way to do string interpolation in AHK2 (eg. command ${arg} --flag ${flag_arg}). Without this, I can't see a way to generate (or even have) an AHK v2 library for komorebic.

For now new users should continue to install AHK v1.1 from the Scoop versions bucket if they want to play around with the sample configurations in this repo.

I will be traveling for most of this month (without a Windows laptop) so I won't be able to do much coding, but if someone can figure out how to handle string interpolation (in any position, not just prepending or appending) in AHK v2, please share the details in this issue.

@LGUG2Z commented on GitHub (Jan 2, 2023): There are some significant changes in AHK2 syntax which require commands to `Run` and `RunWait` to be surrounded by single (or maybe double?) quotes. Unfortunately I have been unable to find a way to do string interpolation in AHK2 (eg. `command ${arg} --flag ${flag_arg}`). Without this, I can't see a way to generate (or even _have_) an AHK v2 library for `komorebic`. For now new users should continue to install AHK v1.1 from the Scoop `versions` bucket if they want to play around with the sample configurations in this repo. I will be traveling for most of this month (without a Windows laptop) so I won't be able to do much coding, but if someone can figure out how to handle string interpolation (in any position, not just prepending or appending) in AHK v2, please share the details in this issue.
Author
Owner

@sitiom commented on GitHub (Jan 3, 2023):

From the docs:

Retrieving the contents of variables: To include the contents of a variable in a string, use concatenation or Format. For example:

MsgBox "The value of Var is " . Var . "."
MsgBox "The value in the variable named Var is " Var "."
MsgBox Format("Var has the value {1}.", Var)

Sub-expressions can be combined with strings in the same way. For example:

MsgBox("The sum of X and Y is " . (X + Y))
@sitiom commented on GitHub (Jan 3, 2023): From the [docs](https://www.autohotkey.com/docs/v2/Variables.htm): > **Retrieving the contents of variables:** To include the contents of a variable in a string, use [concatenation](https://www.autohotkey.com/docs/v2/Variables.htm#concat) or [Format](https://www.autohotkey.com/docs/v2/lib/Format.htm). For example: > ```ahk > MsgBox "The value of Var is " . Var . "." > MsgBox "The value in the variable named Var is " Var "." > MsgBox Format("Var has the value {1}.", Var) > ``` > > Sub-expressions can be combined with strings in the same way. For example: > ```ahk > MsgBox("The sum of X and Y is " . (X + Y)) > ```
Author
Owner

@LGUG2Z commented on GitHub (Jan 19, 2023):

I've been able to use the format AHK fn with variadic args collected into an array to update the code here:

https://github.com/LGUG2Z/komorebi/blob/master/derive-ahk/src/lib.rs#L151

However, this doesn't work consistently, and it completely falls apart when generating trying to generate library functions for commands that require flags:

https://github.com/LGUG2Z/komorebi/blob/master/derive-ahk/src/lib.rs#L132

I have considered just dropping the library altogether and providing a single wrapper command like this:

Komorebi(cmd) {
  RunWait(format("komorebic.exe {}", cmd), , "Hide")
}

; usage
Komorebi("window-hiding-behaviour minimize")

; Change the focused window, Alt + Vim direction keys
!h::
{
  Komorebi("focus left")
}

This works well enough, however when running with an ahk2 interpreter, the focus commands produce access denied errors in komorebi which I am unable to reproduce with either ahk1.1 or just by running the commands in the terminal:

2023-01-19T15:11:13.688842Z ERROR process_command{FocusWindow(Right)}:focus_container_in_direction{direction=Right}: komorebi::window: could not set as foreground window, but continuing execution of focus(): The operation completed successfully. (0x00000000)
2023-01-19T15:11:13.689414Z ERROR komorebi::process_command: Access is denied. (0x80070005)

Is anyone else using ahk2 experiencing this issue when trying to change window focus?

@LGUG2Z commented on GitHub (Jan 19, 2023): I've been able to use the `format` AHK fn with variadic args collected into an array to update the code here: https://github.com/LGUG2Z/komorebi/blob/master/derive-ahk/src/lib.rs#L151 However, this doesn't work consistently, and it completely falls apart when generating trying to generate library functions for commands that require flags: https://github.com/LGUG2Z/komorebi/blob/master/derive-ahk/src/lib.rs#L132 I have considered just dropping the library altogether and providing a single wrapper command like this: ```ahk Komorebi(cmd) { RunWait(format("komorebic.exe {}", cmd), , "Hide") } ; usage Komorebi("window-hiding-behaviour minimize") ; Change the focused window, Alt + Vim direction keys !h:: { Komorebi("focus left") } ``` This works well enough, however when running with an ahk2 interpreter, the focus commands produce access denied errors in `komorebi` which I am unable to reproduce with either ahk1.1 or just by running the commands in the terminal: ``` 2023-01-19T15:11:13.688842Z ERROR process_command{FocusWindow(Right)}:focus_container_in_direction{direction=Right}: komorebi::window: could not set as foreground window, but continuing execution of focus(): The operation completed successfully. (0x00000000) 2023-01-19T15:11:13.689414Z ERROR komorebi::process_command: Access is denied. (0x80070005) ``` Is anyone else using ahk2 experiencing this issue when trying to change window focus?
Author
Owner

@sitiom commented on GitHub (Apr 11, 2023):

Here's a minimum repro script:

#Requires AutoHotkey v2.0.2
#SingleInstance Force

Komorebi(cmd) {
    RunWait(format("komorebic.exe {}", cmd), , "Hide")
}

!h::
{
  Komorebi("focus left")
}

And it seems to work fine.

However, this doesn't work consistently, and it completely falls apart when generating trying to generate library functions for commands that require flags:

master/derive-ahk/src/lib.rs#L132

You also might want to consider using normal string concatenation instead. See 1b9a5ab3de/config/komorebi/komorebic.lib.ahk

@LGUG2Z Can you reopen this issue? I'd really like to have AHKv2 support for library helpers.

@sitiom commented on GitHub (Apr 11, 2023): Here's a minimum repro script: ```ahk #Requires AutoHotkey v2.0.2 #SingleInstance Force Komorebi(cmd) { RunWait(format("komorebic.exe {}", cmd), , "Hide") } !h:: { Komorebi("focus left") } ``` And it seems to work fine. > However, this doesn't work consistently, and it completely falls apart when generating trying to generate library functions for commands that require flags: > > [`master`/derive-ahk/src/lib.rs#L132](https://github.com/LGUG2Z/komorebi/blob/master/derive-ahk/src/lib.rs?rgh-link-date=2023-01-19T16%3A18%3A12Z#L132) You also might want to consider using normal string concatenation instead. See https://github.com/lazuee/dotfiles/blob/1b9a5ab3de5c4b0b77527d36d8b58080fc35fd7a/config/komorebi/komorebic.lib.ahk @LGUG2Z Can you reopen this issue? I'd really like to have AHKv2 support for library helpers.
Author
Owner

@LGUG2Z commented on GitHub (Apr 11, 2023):

Reopening this after some discussion on Discord

The steps moving forward:

  • The derive-ahk crate will be deprecated, both because of the difficulty in updating the syn dependency and because I'm not able to wrangle the raw Rust tokens into the syntax required for v2
  • @lazuee has done a great job of writing an AHKv2 library by hand, which if they have no objections, we'll bring into this repo
  • In the future new komorebic commands should have wrappers manually added to this file
  • The komorebic ahk-asc command will be updated to emit a file in the AHKv2 from the input YAML(s)
  • A simpler wrapper library will also be made available at the project root for users who don't have a dependency on the previous AHKv1 library format
  • Readme section will be added explaining how to use these libraries with AHK
@LGUG2Z commented on GitHub (Apr 11, 2023): Reopening this after some [discussion on Discord](https://canary.discord.com/channels/898554690126630914/898554690608967786/1095157412211740743) The steps moving forward: - [ ] ~~The `derive-ahk` crate will be deprecated, both because of the difficulty in updating the `syn` dependency and because I'm not able to wrangle the raw Rust tokens into the syntax required for v2~~ - [x] @lazuee has done a great job of [writing an AHKv2 library by hand](https://github.com/lazuee/dotfiles/blob/1b9a5ab3de5c4b0b77527d36d8b58080fc35fd7a/config/komorebi/komorebic.lib.ahk), which if they have no objections, we'll bring into this repo - [ ] ~~In the future new `komorebic` commands should have wrappers manually added to this file~~ - [x] The `komorebic ahk-asc` command will be updated to emit a file in the AHKv2 from the input YAML(s) - [ ] A [simpler wrapper library](https://github.com/LGUG2Z/komorebi/issues/324#issuecomment-1397236894) will also be made available at the project root for users who don't have a dependency on the previous AHKv1 library format - [x] Readme section will be added explaining how to use these libraries with AHK
Author
Owner

@sitiom commented on GitHub (Apr 17, 2023):

Might as well bring back komorebi.sample.ahk for AHKv2

@sitiom commented on GitHub (Apr 17, 2023): Might as well bring back [`komorebi.sample.ahk`](https://github.com/LGUG2Z/komorebi/blob/v0.1.14/komorebi.sample.ahk) for AHKv2
Author
Owner

@NormTurtle commented on GitHub (Apr 17, 2023):

so are we losing whkd ? again ???

@NormTurtle commented on GitHub (Apr 17, 2023): so are we losing whkd ? again ???
Author
Owner

@LGUG2Z commented on GitHub (Apr 17, 2023):

so are we losing whkd ? again ???

Don't worry, this is not the case. This PR is just to add the same level of support for AHKv2 that users previously had with AHKv1.

@LGUG2Z commented on GitHub (Apr 17, 2023): > so are we losing whkd ? again ??? Don't worry, this is not the case. This PR is just to add the same level of support for AHKv2 that users previously had with AHKv1.
Author
Owner

@LGUG2Z commented on GitHub (May 2, 2023):

This is in the master branch now and will be part of the upcoming 0.1.16 release. I'm planning on making an AHK quickstart video to go along with it as well. 🚀

@LGUG2Z commented on GitHub (May 2, 2023): This is in the master branch now and will be part of the upcoming 0.1.16 release. I'm planning on making an AHK quickstart video to go along with it as well. 🚀
Author
Owner

@NormTurtle commented on GitHub (May 3, 2023):

so what about win + keys?!

@NormTurtle commented on GitHub (May 3, 2023): so what about win + keys?!
Author
Owner

@sitiom commented on GitHub (May 3, 2023):

so what about win + keys?!

You can use the Win key as a keybinding in AHK

@sitiom commented on GitHub (May 3, 2023): > so what about win + keys?! You can use the Win key as a keybinding in AHK
Author
Owner

@llinfeng commented on GitHub (Jul 5, 2024):

Hi folks, I'm new to komorebi and have been using my decade-old AHK v1 script to manage the window-layout until now. I'd prefer to stay with AHK v1 for the time being.

What would be a good pointer for AHK v1 configuration? I tried to search around and only found this commit (acc119a) through this search, with keyboard "ahk1".

Will the ahk filies files associated with commit acc119a work for komorebi in its current state? There are a good number of them, including komorebi.generated.ahk, komorebi.sample.ahk, and komorebic.lib.ahk. In particular, will these old AHK v1 config still work for the current komorebi executable, which I installed using the following lines as suggested in the readme:

winget install LGUG2Z.komorebi
winget install LGUG2Z.whkd

Thx!

@llinfeng commented on GitHub (Jul 5, 2024): Hi folks, I'm new to `komorebi` and have been using my decade-old AHK v1 script to manage the window-layout until now. I'd prefer to stay with AHK v1 for the time being. **What would be a good pointer for AHK v1 configuration?** I tried to search around and only found [this commit (`acc119a`)](https://github.com/LGUG2Z/komorebi/commit/acc119a5294a364d84b170a44e2d3b925c6808e1) through [this search, with keyboard "ahk1"](https://github.com/search?q=repo%3ALGUG2Z%2Fkomorebi+ahk1&type=commits). Will the ahk filies files associated with commit [acc119a](https://github.com/LGUG2Z/komorebi/tree/acc119a5294a364d84b170a44e2d3b925c6808e1) work for `komorebi` in its current state? There are a good number of them, including [komorebi.generated.ahk](https://github.com/LGUG2Z/komorebi/blob/acc119a5294a364d84b170a44e2d3b925c6808e1/komorebi.generated.ahk), [komorebi.sample.ahk](https://github.com/LGUG2Z/komorebi/blob/acc119a5294a364d84b170a44e2d3b925c6808e1/komorebi.sample.ahk), and [komorebic.lib.ahk](https://github.com/LGUG2Z/komorebi/blob/acc119a5294a364d84b170a44e2d3b925c6808e1/komorebic.lib.ahk). In particular, will these old AHK v1 config still work for the current `komorebi` executable, which I installed using the following lines as suggested in the readme: ``` winget install LGUG2Z.komorebi winget install LGUG2Z.whkd ``` Thx!
Author
Owner

@LGUG2Z commented on GitHub (Jul 5, 2024):

I would recommend using this as your starting point now: https://lgug2z.github.io/komorebi/common-workflows/autohotkey.html

Just rewrite this function to be compatible with AHKv1:

Komorebic(cmd) {
    RunWait(format("komorebic.exe {}", cmd), , "Hide")
}

Then you call it with the same arguments that you'd call the regular komorebic commands as listed here: https://lgug2z.github.io/komorebi/cli/quickstart.html

If you set the KOMOREBI_AHK_EXE variable to the path to your AHKv1 executable you should be good to go.

@LGUG2Z commented on GitHub (Jul 5, 2024): I would recommend using this as your starting point now: https://lgug2z.github.io/komorebi/common-workflows/autohotkey.html Just rewrite this function to be compatible with AHKv1: ```ahk Komorebic(cmd) { RunWait(format("komorebic.exe {}", cmd), , "Hide") } ``` Then you call it with the same arguments that you'd call the regular komorebic commands as listed here: https://lgug2z.github.io/komorebi/cli/quickstart.html If you set the [`KOMOREBI_AHK_EXE` variable](https://github.com/search?q=repo%3ALGUG2Z%2Fkomorebi%20KOMOREBI_AHK_EXE&type=code) to the path to your AHKv1 executable you should be good to go.
Author
Owner

@llinfeng commented on GitHub (Jul 7, 2024):

Update: for AHK 1, keeping the following function somewhere before calling Komorebic("CLI-arguments") suffices:

Komorebic(cmd) {
    RunWait, % "komorebic.exe " cmd,, Hide
}
@llinfeng commented on GitHub (Jul 7, 2024): Update: for AHK 1, keeping the following function somewhere before calling `Komorebic("CLI-arguments")` suffices: ``` Komorebic(cmd) { RunWait, % "komorebic.exe " cmd,, Hide } ```
Author
Owner

@sitiom commented on GitHub (Jul 8, 2024):

Perhaps it would be a better investment to switch to AHK v2 😅; it would only take a day to port all your scripts at best. You can check out https://github.com/mmikeww/AHK-v2-script-converter to help you out with it.

@sitiom commented on GitHub (Jul 8, 2024): Perhaps it would be a better investment to switch to AHK v2 😅; it would only take a day to port all your scripts at best. You can check out https://github.com/mmikeww/AHK-v2-script-converter to help you out with it.
Author
Owner

@llinfeng commented on GitHub (Jul 8, 2024):

@sitiom Thank you for the pointer to the converter repo. It looks promising. I agree that I should switch to AHK v2 at some point.

@llinfeng commented on GitHub (Jul 8, 2024): @sitiom Thank you for the pointer to the converter repo. It looks promising. I agree that I [should](https://gist.github.com/Lexikos/a871ca393387b37204ccb4f36f2c5ddc) switch to AHK v2 at some point.
Author
Owner

@DovieW commented on GitHub (Oct 10, 2024):

@llinfeng Did you end up making the ahk1 config? I have ahk1 installed on my work PC and would be a pain to get ahk2 installed.

Would you be able to post it here if so? If it's not too much trouble

@DovieW commented on GitHub (Oct 10, 2024): @llinfeng Did you end up making the ahk1 config? I have ahk1 installed on my work PC and would be a pain to get ahk2 installed. Would you be able to post it here if so? If it's not too much trouble
Author
Owner

@llinfeng commented on GitHub (Oct 10, 2024):

@DovieW, I think the following will do the trick for AHK v1.

; Section for interacting with Komorobi
Komorebic(cmd) {
    RunWait, % "komorebic.exe " cmd,, Hide
}

; Then, these may just work
; Focus windows
!h::Komorebic("focus left")
!j::Komorebic("focus down")
!k::Komorebic("focus up")
!l::Komorebic("focus right")

; Move windows
!+h::Komorebic("move left")
!+j::Komorebic("move down")
!+k::Komorebic("move up")
!+l::Komorebic("move right")
@llinfeng commented on GitHub (Oct 10, 2024): @DovieW, I think the following will do the trick for AHK v1. ``` ; Section for interacting with Komorobi Komorebic(cmd) { RunWait, % "komorebic.exe " cmd,, Hide } ; Then, these may just work ; Focus windows !h::Komorebic("focus left") !j::Komorebic("focus down") !k::Komorebic("focus up") !l::Komorebic("focus right") ; Move windows !+h::Komorebic("move left") !+j::Komorebic("move down") !+k::Komorebic("move up") !+l::Komorebic("move right") ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/komorebi#171