AHK_X11, AutoHotkey for Linux

Discuss Autohotkey related topics here. Not a place to share code.
Forum rules
Discuss Autohotkey related topics here. Not a place to share code.
User avatar
phil294
Posts: 7
Joined: 21 Jul 2022, 04:12
Contact:

AHK_X11, AutoHotkey for Linux

Post by phil294 » 21 Jul 2022, 20:21

Hi!

I want to share with you this current project of mine. You can find it here: https://github.com/phil294/AHK_X11. The GitHub Readme has quite thorough information on it, but I'll quote some parts of it here anyway. You can open up issues over there for bugs, feature requests etc., but I'll also check this very thread and maybe Discord.

  • A rudimentary but functional implementation of AutoHotkey v1.0.24. This version is ancient: 2004.
    You can check the old manual by installing or extracting the old `.chm` manual from [here].
    Many modern AHK features will be missing, especially expressions (`:=` or `% v`) and functions, so you probably can't just port your scripts from Windows. Maybe this will also be added some day, but it does not have high priority for me personally. Mixing these syntaxes is also not a great idea, as we have all learned... Some of the more modern features would certainly be helpful though, such as RegEx (definitely gonna add this one) or ImageSearch.
  • In other words, at least initially, AHK_X11 supports *only legacy syntax*. Some folks have already tried to stop me from taking that route, but to no avail, I'm afraid :D Please forgive me. I still think it's the right strategy.
  • for Unix-like systems with an X window system (X11)
  • written from ground up in Crystal. It shares no code with normal AHK or any other program.
  • With the eventual goal of 80% feature parity with that old spec, but most likely never full compatibility.
  • Everything that can't be easily translated into Linux (surprisingly little) will simply be skipped
  • No automatic tests for now
  • It is/will be shipped as a single executable native binary with very low resource overhead and fast execution time.
All the points above enable a super quick, feature-packed iteration time and as little of effort as possible for finally getting some form of AHK on Linux. Please understand that despite its minimalist approach, this was, is and will be a lot of work, so unless someone wants to pay me full time to work on it, it will be an incomplete patchwork for an extended time. It's GPL-licensed, so I want to encourage others to join in or fork it for their purposes. There's a small section on Contributing in the Readme also.

Note on Keysharp: I think the differences to Keysharp should be pretty obvious by now, both in philosophy and technology, in v2 syntax and target operating systems, target audience and ambitions. If @mfeemster continues his amazing dedication, Keysharp will most likely be superior to AHK_X11 in most aspects. I consider this a positive development. Perhaps I can help out on the Linux side of things some day.

Contrary to previous belief I have encountered on these forums, it is not necessary to manually cater all different Linux distributions. AHK_X11 targets the X display server that all those distros use anyway. The window or display manager is irrelevant. The integration is also not particularly cumbersome either. After endlessly reading up on various topics, the event loop, hotkey parsing, registration etc. was only a few lines. Crystal rocks!

For current status, please check the Readme. I plan on postponing GUIs and instead finishing Hotkeys and `Send` and many Windows and Files commands first. I'd also like to take the old docs, convert them into HTML, add colorful notes showing which features are done, added, missing or altered and link it as a single page somewhere so you get instant complete documentation access. However, I also don't want to get into trouble (license?) by publishing and posting outdated documentation that might confuse Windows users some day...

TL;DR: Not usable yet, but will probably start to be useful already quite soon (granted I get libxdo working).

burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: AHK_X11, AutoHotkey for Linux

Post by burque505 » 23 Jul 2022, 07:24

@phil294, that's welcome news, thanks for your effort. I look forward to your progress.
Regards,
burque505

ferosuchiki
Posts: 1
Joined: 24 Jul 2022, 02:35

Re: AHK_X11, AutoHotkey for Linux

Post by ferosuchiki » 24 Jul 2022, 02:37

Just what I'm looking for! I installed Ubuntu last night and all that exist already does not meet my requirement xD AHK got exactly what I need :D You are a saint for making this :D I'd even go so far as paying for this xD

Geeksi
Posts: 3
Joined: 08 May 2020, 03:14

Re: AHK_X11, AutoHotkey for Linux

Post by Geeksi » 25 Jul 2022, 06:25

work perfect

User avatar
phil294
Posts: 7
Joined: 21 Jul 2022, 04:12
Contact:

Re: AHK_X11, AutoHotkey for Linux

Post by phil294 » 19 Aug 2022, 23:08

Hellou,
quick update: The following features are now implemented.

- Hotkeys, Hotstrings
- Compiler (create portable binaries)
- Installer
- Full docs
- Send
- GUIs (parts)
- Tray icon
- REPL (command line)

Most autonomous commands are still missing, but it's definitely ready for testing by now. I don't think much will change anymore apart from command coverage.

SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: AHK_X11, AutoHotkey for Linux

Post by SOTE » 25 Aug 2022, 03:00

Great idea and demonstration, including usage of Crystal. I think you should go as far with AHK "Classic", as you can. There is the nostalgia aspect, like when people bring back classic games, and it could also provide a very useful baseline of ported over features. Thus the project becoming a reference point, including it being helpful to many people. Additionally, it brings up the possibility of macOS and Android versions (if Linux subsystems added to Android's Linux kernel). So an AHK Classic variant could be out there with @mfeemster's AHK v2 offshoot (Keysharp).

Would also be nice to see you collaborate or team up with Mfeemster at some point in the future.

Mimiko
Posts: 11
Joined: 09 Dec 2020, 10:37
Contact:

Re: AHK_X11, AutoHotkey for Linux

Post by Mimiko » 06 Sep 2022, 05:13

Excellent
Now it's natively cross-platform!

skribb
Posts: 28
Joined: 22 Jun 2016, 20:52

Re: AHK_X11, AutoHotkey for Linux

Post by skribb » 24 Sep 2022, 14:24

phil294 wrote:
19 Aug 2022, 23:08
Hellou,
quick update: The following features are now implemented.

- Hotkeys, Hotstrings
- Compiler (create portable binaries)
- Installer
- Full docs
- Send
- GUIs (parts)
- Tray icon
- REPL (command line)

Most autonomous commands are still missing, but it's definitely ready for testing by now. I don't think much will change anymore apart from command coverage.
looking forward to the developments :D

Mimiko
Posts: 11
Joined: 09 Dec 2020, 10:37
Contact:

Re: AHK_X11, AutoHotkey for Linux

Post by Mimiko » 01 Oct 2022, 10:29

@phil294
It's rly a small world.
I have a project to compile coffeescript to ahk called coffee-ahk.
And because of your CoffeeSense project, it can now get type checking for typescript, making it possible to make ahk scripts with static types.
I'm still experimenting with this aspect, but it's really kinda cool.

picklepissjar
Posts: 20
Joined: 22 Oct 2022, 10:03

Re: AHK_X11, AutoHotkey for Linux

Post by picklepissjar » 27 Feb 2023, 12:59

I've been using this and Autokey to try and fill the role that AutoHotKey serves when I use Windows. However, there was one function that I couldn't replicate, https://www.autohotkey.com/board/topic/15574-morse-find-hotkey-press-and-hold-patterns/ . The function executes different commands based on the morse pattern (2xPress, Long Press, etc.). So, I made my own implementation of it in C that monitors /dev/input (X11 only shows KeyPress & KeyRelease). https://github.com/picklepissjar/ev-morse Hope this can help others on Linux. :thumbup:

User avatar
phil294
Posts: 7
Joined: 21 Jul 2022, 04:12
Contact:

Re: AHK_X11, AutoHotkey for Linux

Post by phil294 » 28 Feb 2023, 10:02

picklepissjar wrote:
27 Feb 2023, 12:59
I've been using this and Autokey to try and fill the role that AutoHotKey serves when I use Windows. However, there was one function that I couldn't replicate, https://www.autohotkey.com/board/topic/15574-morse-find-hotkey-press-and-hold-patterns/ . The function executes different commands based on the morse pattern (2xPress, Long Press, etc.). So, I made my own implementation of it in C that monitors /dev/input (X11 only shows KeyPress & KeyRelease). https://github.com/picklepissjar/ev-morse Hope this can help others on Linux. :thumbup:
That's a sweet tool! I might even use this as reference for adding Wayland support.

However, you should know that this morse functionality is very much possible with AHK_X11. Here's what I could come up with:

Code: Select all

Return

Morse:
   timeout = 400
   tout = %timeout%
   tout /= 1000.0
   Pattern =
   Loop
   {
      t = %A_TickCount%
      KeyWait %key%
      time_passed = %A_TickCount%
      time_passed -= %t%
      If time_passed > %timeout%
         Pattern = %Pattern%L
      Else
         Pattern = %Pattern%S
      KeyWait %key%,DT%tout%
      If ErrorLevel = 1
         Return
   }
Return

~!z::
   Hotkey, ~!z, OFF
   key = z
   GoSub Morse
   If Pattern = S
      MsgBox Short press
   Else If Pattern = SS
      MsgBox Two short presses
   Else If Pattern = SL
      MsgBox Short+Long press
   Else
      MsgBox Press pattern %pattern%
   Hotkey, ~!z, ~!z
Return
A few workarounds were necessary because we don't support
1. Functions ("Morse()")
2. Expressions ("Pattern .= A_TickCount-t > timeout")
3. A_ThisHotKey (I should really add this)
4. KeyWait only works on the same Hotkey if it's non-grabbing. In other words, the ~ is necessary. That's because of this bug, I'm not yet sure if it is fixable
5. Strict string comparison ("0 == 00" is always true), so I changed it to S and L instead
6. #MaxThreadsPerHotkey (should be default 1, but it's currently default unlimited). So a "Hotkey, !z, OFF" and "ON" is added

With all of this, it works great!

picklepissjar
Posts: 20
Joined: 22 Oct 2022, 10:03

Re: AHK_X11, AutoHotkey for Linux

Post by picklepissjar » 01 Mar 2023, 16:00

:bravo: Dang.
I guess I didn't try hard enough in my attempts (didn't try gosub). :lol:
I will definitely be using this. Tyvm

omar
Posts: 537
Joined: 22 Oct 2015, 17:56

Re: AHK_X11, AutoHotkey for Linux

Post by omar » 26 Mar 2023, 08:44

Big thanks for trying to make this happen. I'll bookmark this thread.
Linux desperately missed AHK type of functionality.
Would be amazing if you moved onto Mac next :)

fernsehen123
Posts: 22
Joined: 24 Mar 2018, 13:50

Re: AHK_X11, AutoHotkey for Linux

Post by fernsehen123 » 02 Apr 2023, 09:16

omar wrote:
26 Mar 2023, 08:44
Big thanks for trying to make this happen. I'll bookmark this thread.
Linux desperately missed AHK type of functionality.
Would be amazing if you moved onto Mac next :)
I need this for MacOs as well :mrgreen:

User avatar
phil294
Posts: 7
Joined: 21 Jul 2022, 04:12
Contact:

Re: AHK_X11, AutoHotkey for Linux

Post by phil294 » 20 Jul 2023, 09:39

Just released version 1.0.0: https://github.com/phil294/AHK_X11/releases/tag/1.0.0

This was the last big update, probably ever. Now *most* things are working and implemented, even funny stuff like RunAs.

I have also worked on Wayland support a bit and it can be tested out in a preview version here https://github.com/phil294/AHK_X11/releases/tag/0.5.99-next but I don't recommend it. Will still take a while until it runs on Wayland.
omar wrote:
26 Mar 2023, 08:44
Would be amazing if you moved onto Mac next :)
No chance. However, maybe it runs partially with XQuartz?
Mimiko wrote:
01 Oct 2022, 10:29
It's rly a small world.
hah yes It really is :)

Anyway, thanks for the friendly feedback everyone

NagaSuka
Posts: 15
Joined: 15 Oct 2017, 13:09

Re: AHK_X11, AutoHotkey for Linux

Post by NagaSuka » 22 Sep 2023, 07:24

Great job! :bravo:

Autohotkey is a top missing thing for me in Linux.

Do you plan to create deb. ?

I have used MX Linux for 3 years as a normal user. It's a rock-stable distro when you never install anything from outside the repository of MX or Debian. In the past I used to be more into experimenting and experienced the pain of breaking out my system (and how much time it consumes), so I will patiently wait for AHK_X11 in the official repository as long as needed.

User avatar
phil294
Posts: 7
Joined: 21 Jul 2022, 04:12
Contact:

Re: AHK_X11, AutoHotkey for Linux

Post by phil294 » 22 Sep 2023, 09:24

Hi, thank you! No, not planned. That would mean I have to keep track of all of its dependencies, make separate packages for all Debian versions, update them after breaking abi version changes, and also do the same thing for all other 5925135 Linux distributions, resulting in 88791235 different packages. It's a never-ending process that I will gladly delegate to those who are into pain, because that doesn't include me.

That's why I wouldn't wait for it to appear in the "official" repositories, as that would be even several steps further: Not just a `.deb` / PPA, but part of the actual Debian packages. I can't see how that would ever happen (prove me wrong); just use the AppImage build. There will be an AUR package for Arch Linux users soon, at least.

Instead, there is only a single build using AppImage. It should run on any Linux distro, hopefully forever (you might need to do `sudo apt install libfuse2` depending on your system, but that may soon also be resolved). So no experimenting should be required.

There's also the option of building from source using the provided Makefile. Depending on the selected build target, this may not, however, result in an AppImage and thus require rebuilds after a while, and also fails to produce cross-distro-portable ahk compiled binaries.

NagaSuka
Posts: 15
Joined: 15 Oct 2017, 13:09

Re: AHK_X11, AutoHotkey for Linux

Post by NagaSuka » 22 Sep 2023, 13:17

As a humble normal Linux user, I was not aware of 5925136 Linux distributions, resulting in 88791235 packages. I was thinking that one .deb can be used by Debian derivatives. Everybody is afraid of different pain. I don't feel competent for further discussion about dependencies.

You made the best available automation tool for Linux, so: respect.

User avatar
xMaxrayx
Posts: 136
Joined: 06 Dec 2022, 02:56
Contact:

Re: AHK_X11, AutoHotkey for Linux

Post by xMaxrayx » 05 Dec 2023, 02:33

@NagaSuka

why just use Flatpak its great for small devs to share their app?

deb , aur , rpm need a lot of works aka more devs
-----------------------ヾ(•ω•`)o------------------------------
https://github.com/xmaxrayx/

Post Reply

Return to “General Discussion”