AHK lets you run arbitrary code in response to global hotkeys. There is no wayland protocol for applications to register global hotkeys for themselves. Compositors can choose to provide their own hotkey configurations, and what you can do in response to those hotkeys being pressed depends on the compositor. For example in Sway you can register hotkeys to run arbitrary executables. Alternatively, XDP apparently has a portal API for applications to register global hotkeys, but of course it's up to the individual compositors' portal implementations if they implement the API. For example xdpw, used for all wlroots-based compositors like sway, does not.
AHK lets you read and set the mouse position. There is currently no wayland protocol, stable or unstable, for programs to read or set the position of a pointer (if the pointer is not over the program's surface).
AHK lets you introspect arbitrary windows to read the text of a focused textbox, etc. There is currently no protocol, stable or unstable, for programs to implicitly grab the content of surfaces under the pointer, let alone read text of textboxes. At best you can use the XDP Screencast protocol but that only gives you images (AHK integrates with the standard Windows graphics UI API so it can detect textboxes etc), and even then it might pop up a permissions dialog for the user to approve like you would expect for a screencasting program.
AHK lets you insert arbitrary keyboard sequences into the focused window. There is no Wayland protocol for this, but you can just use a new input device through the uinput kernel driver instead of anything Wayland-specific. (ydotool does this.)
AHK lets you read and write to the clipboard. There is an (unstable) wayland protocol for clipboard managers that can be used for this.
> There is currently no protocol, stable or unstable, for programs to implicitly grab the content of surfaces under the pointer, let alone read text of textboxes.
Yes there is, AtSpi, the accessibility protocol. But a normal window-independent `Click, X, Y` would indeed be quite important to have...
I'm wondering if there is a way to somehow get active window position, move windows around etc. using root privileges, without relying on a custom compositor extension. Could not find anything.
Examples I use: 3 finger swipe to left/right switches desktop in Sway, rebinding caps to esc.
Discussion and link at https://news.ycombinator.com/item?id=32654023
So many great quality of life improvements and overall the documentation is top notch. I cobbled together a launcher app and modal-hotkey system from scratch in a couple of afternoons of enjoyable work.
If you're looking to try stuff out, having an autoreload function is a very nice addition to your script while developing.
A very pragmatic and productive experience.
Some of the scripts I use daily are in Python, and some are in AHK. The AHK documentation is much easier to follow than the Python documentation IMO.
Really it isn’t much more than an abuse of the Hotkey function and (effectively) function pointers.
I’ll put it up this evening though if people want to peep at it.
[Edit] In case people miss the other reply it's here: https://github.com/url00/ModalAHK
I'm taking a month off from development while I'm traveling, maybe I'll feel less salty about this when I get back.
The biggest issue right now is that the Run and RunWait commands require strings for the commands to be executed, and AHK v2 has absolutely garbage support for string interpolation.
Honestly I'm not sure if I'll continue supporting AHK or just develop my own sxhkd (swhkd?) and recommend that for users going forward.
[1]: https://github.com/LGUG2Z/komorebi
[2]: https://github.com/LGUG2Z/komorebi/blob/master/komorebic.lib...
But I would definitely not recommend converting v1 scripts to v2 if is not absolutely necessary.
You can have both installed and work great with the new launcher that auto selects version based on the #Requires directive.
I would definitely not convert v1 scripts that are longer than 2k lines.
What I have found is that re-writing stuff for v2 is WAY easier than converting.
You might also try the v1 -> v2 converter by dimitri. It is not perfect but does 90% of the work for ya.
e.g.: #Requires Autohotkey v1.1.36+ 32-Bit
When you install v2 it has a launcher that can be configured and runs scripts with the correct interpreter based on that directive.
If that directive is not in the script it would try to determine the version based on syntax. And if it couldnt determine it, it would ask you what to do.
I have both versions installed and have had no issues as of yet.
Python is from 1991. Python 2 (from 2000) was not a breaking change if I'm skimming the "what's new in python 2.0" correctly. Python 2 was supported until 2020 (29 years).
Autohotkey from 2003 (19 years old now).
Unless AHKv1 is still maintained, Python wins by a decade.
All you have to do set up an AHK script is open up notepad, type a hotkey symbol, then some basic commands like “Click <X>, <Y>” or “Send <keystrokes>”, save the file, and double click to run. Doesn’t get much simpler. Loops and routines can be learned over time as needed, and aren’t necessary to meet most people’s use cases.
1) executed in a clear, top-down fashion, allowing to write code top-level, without wrapping it in functions and calling from an explicit entry point like main();
2) interfaced directly with the useful APIs, vs. having to manage libraries and namespaces;
3) interpreted directly from the source file, as opposed to having first run a compiler or other explicit, artifact-producing step;
Basically, languages that would let me just write minimum amount of code to solve, through trial and error and experimentation, my simple problems.
I believe this is where some Lisp language would shine, if not for the fact that you have to press SHIFT to enter parentheses... I suspect this is a large reason people ended up preferring scripting languages with punctuation that can mostly be entered without modifier keys.
AutoCAD - true
Photoshop - true
SketchUp - true
AHK - not so much.
Autokey does what I need. But I still have great time for AHK - which is why I looked at this thread. Yeah, there's GIMP and Blender and SU online but these applications were really ace on Windows. I found a way to live without them all.
I'm not willing to sacrifice my productivity for some ideological purity.
It would take weeks to create a fraction of what AHK already does for me with scripts I have improved every year.
I tried to explain in another thread some of the remappings I have: like how Caps often ends us remapped to Esc (when alone) or Control (in conjunction with another key: act as a modifier) on MacOS, my 2 shifts and 2 alt do their normal modifier function (when used in conjunction with another key) but when used by themselves act as PageUp/PageDown Home/End
Going up 2 pages up in the browser? The left shift pressed twice (Shift Shift) gives me 2 PageUp. Top of the page? Alt gives me Home. Bottom? The other Alt gives me End. Select from the point of edition to the beginning? Shift+Alt does Shift + Home. It's not the homerow, but it's 2 keys easy to reach, and never missing (unlike the actual PageUp which is often Fn + something - no I don't want to turn that into 3 or 4 keys).
Yes, doing Cap s=> Esc or Control is possible on Linux, but the rest will be complicated.
And it's just one of the many things AHK does for me! Here's another example: a partial screenshot into a base64 encoded PNG is just 2 keys away.
It might be possible to do all that on Linux, but last time I tried to get something a fraction as good as mintty (with ligatures, italic, sixels...) the best I could get was a pimped xterm.
For what I do, the tooling is just much better on Windows - and yes, you may not believe it, but even for tty/console things.
Most of them aren't free and I haven't found any of them to be better than AHK, but they do the job well enough that it's certainly not a reason to look back fondly to Windows despite my lack of enthusiasm for MacOS.
But I got AHK running in Wine on Linux, and on another Linux machine with Wayland I got simple rebinds and simple scripts working with keyboard and mouse (which I could extend with say Python scripts from AutoKey?). Its more difficult on Linux, but its possible.
> AutoHotkey v2 aims to improve the usability and convenience of the language and command set by sacrificing backward compatibility. As such, scripts written for v1 generally will not work without changes on v2
Just a few days ago I was complaining¹ about how Excel handles formula input. After some back and forth on my yak-shaving attempt, I realized I could shave it myself with AHK.
With this little bit of code, my [Enter] and [Tab] keys work the way I want them to in Excel. This is still version 1.1, not 2.0:
; Try to "fix" Excel formula bar
; ==============================
IsExcelFormulaBox()
{
ControlGetFocus, F, A
return (F="EXCEL<1")
}
#if IsExcelFormulaBox()
Tab::
; Look for the little function list that pops up when suggestions are available.
ControlGet, X, Visible,, SysListView321, ahk_class __XLACOOUTER
; If list is visible, then pass [Tab] through. If not, insert 4 spaces
if (X) {
Send {Tab}
} else {
Send {Space}{Space}{Space}{Space}
}
return
; Swap [Enter] and [Alt]+[Enter]
$!Enter::Send {Enter}
$Enter::Send !{Enter}
#if
[1] https://news.ycombinator.com/item?id=34176791I have HUNDREDS of little AHK hotkeys. I use some of them dozens of times a day. I've been wanting some way to directly target Excel like this for literal years.
Thank you!!!
I’ll bet I find more weird corner cases with this hot key. My first attempt didn’t handle the autocomplete, and that was a big letdown until I found the workaround. I’m sure I’ll run into something else as well.
I found a +-300 line script which allowed me to play with a controller (made by zarzare), I modified it for the different classes and it worked ridiculously well. It used basic trig to create a circle around the player's position and cast abilities in that direction. You could specify a short/long range so abilities could be cast either short or far, depending on the range of the ability.
The latest was Crowdstrike Falcon (AI POWERED!!1) flagging signtool.exe as malware. The one from the Windows SDK. By Microsoft. Signed with Microsoft keys.
Yes. I don't remember the details but there was one time where it prevented me from executing some download that was malicious. This was more than a decade ago.
On another occasion (around the same time) it failed to prevent malware from executing. I never found out what the method of infection was, but after changing back the wallpaper and removing it from startup programs, I suffered no further ill effects... fifteen year old me was not very thorough but seems to have worked anyway.
And then there are the numerous annoyance occasions where it false-positived on legitimate software like Nirsoft, Cain&Abel, Netcat, Nmap, etc. Not to mention corporate proxies blocking my personal link shortener but being fine with bitly. Security theatre, those are.
To be fair, AV also prevents executing standard metasploit things and attackers have to be a bit more creative which gets tedious and so it can be an indicator of compromise to have this pop an alert even if the attacker succeeds a few minutes later.
Crowdstrike helped us a few times to contain serious issues, and made me difficult for people as well because it blocked their "suspicious" behaviour.
The bad guys only need to succeed once.
For more than 99% of their install base its presence on a system may be a decent indicator of compromise. Maybe not worth flagging by itself but worth investigating anything that bundled it.
It'll be a while before I give it a try, because it sounds like I'll have to convert a bunch of stuff- but I'm definitely going to give it a try. I'm just overjoyed that AHK is in active development still! Been using it for well over a decade.
My Favorite Use of AHK
2014. My grandfather was in his mid-80's. He lost dexterity in his hands, and was having a very difficult time because he was clicking both left and right mouse buttons at the same time.
AHK to the rescue! I re-mapped right mouse button to nothing, effectively disabling it. Then, I mapped NumPad+ to the right mouse button. If he needed to right click, he just pointed, pressed NumPad+. Otherwise, he could click both buttons all day long and the computer operated just fine.
He got a few more months use out of that before he passed away, and it remains the most meaningful computer fix of my entire career. I miss that man. A lot.
It's been a while so perhaps the situation w/ linux and OSX has improved, but IIRC linux was very fragmented/finnicky and OSX is absurdly overzealous on permissions so you can never get anything useful done.
I'm constantly frustrated by the enormous gulf between what my computer COULD do vs what it actually CAN do because of how much stupid wall building everyone does. AHK is one of the few things that meaningfully bridges that gap. There are so many things that are infinitely frustrating because you have to click through like 10 menus instead of issuing a simple API command, and with AHK you can get some of that back.
We live in a world where 9 times out of 10 I won't open Premiere or whatever, because it's so much faster to just use ffmpeg. I want a world where Premiere still has all it's ui shit, but also has a decent scripting interface. It's one of the reasons I'm so bullish on Blender in the 3DCG space. The scriptability/extensibility is so far ahead of everything except Houdini.
I hope that this upgrade will fix some of these problems. I'll probably take a few years before I upgrade my AHK scripts.
I always wonder in these discussions why bourne shell/bash gets a pass. Many people know it, but are somehow blind to how terrible it is.
The most complicated pay for me are braces and delimiters: I never know when to use a brace, when to use style #-delimiters (#HotIf for instance), when a mineral is enough, etc.
It would be much better if there was a decision to be homogenous and always require braces, or newlines or whatever - but always the same thing.
Shameless plug: my script for emulating a trackball with your keyboard [0], and my tray app for quickly tweaking your cursor speed (usually for when I'm drawing something)[1]
There are also some really useful utility apps like WhyNotWin11[2] that's made entirely using AutoIt
[0] https://github.com/EsportToys/TPMouse
[1] https://github.com/EsportToys/MouseTray
[2] https://github.com/rcmaehl/WhyNotWin11What community it does have is extremely and openly hostile towards newbies and non-programmers. To the point where browsing their forums has become a huge turn-off, and definitely has rejected folks trying to learn programming and/or AutoIt.
Even experienced programmers sometimes ask "dumb" questions... and the hostility they're met with is unacceptable.
> One function may be defined inside another. A nested function may automatically "capture" non-static local variables from the enclosing function (under the right conditions), allowing them to be used after the enclosing function returns.
That sounds like a closure. I expected “nested” to mean that the function is defined inside another function but doesn’t capture anything, like what you can do in Rust. (It’s IMO a “why not?” feature—why don’t more languages allow it? It’s certainly useful for helper functions which are only consumed by one other function.)
; Map CapsLock key to Control
CapsLock::Ctrl
; Ctrl + Alt + Arrow key jumps to beginning/end of line/document;
; Add Shift to select as well
^!Left::SendInput, {Home}
^!Up::SendInput, ^{Home}
^!+Left::SendInput, +{Home}
^!+Up::SendInput, ^+{Home}
^!Right::SendInput, {End}
^!Down::SendInput, ^{End}
^!+Down::SendInput, ^+{End}
^!+Right::SendInput, +{End}
On any PC without these running I feel hobbled. It's like my shoelaces are tied together or something.I learned programming with AHK back before data structures like maps and arrays even existed (!), and I'm happy to see it's still getting better. I still use a few utilities that I built on a daily basis.
We had an old Tadiran phone system, and it was losing time. Randomly through the day it would lose anywhere from five minutes to two hours.
Of course, the system wasn't under maintenance any longer, and the phone place wanted $4,000 for a new motherboard (the crystal was bad so the clock was wrong, or so they said). Considering everything else worked fine, we just manually set the clock here and there.
And then I found AHK, and wrote a quick script that logged into the phone software, entered the correct time, and saved it to the system. Set that to run every hour and ever heard anyone complain about it again.
I do wish programmers had more options in general for this kind of thing. I ran into https://github.com/autopilot-rs/autopilot-rs lately but it is extremely simple. On Windows there s UI Automation, which can help script many conventional apps. https://learn.microsoft.com/en-us/dotnet/framework/ui-automa...
I have a ~5000loc script that I've been planning to rewrite, but there was never much reason except stability. But I guess now is the right time!
I am still looking for some modern AI OCR for AHK, because the solutions that I've found this far hasn't really worked well.
I must say, working with AHK is always fun, even though not implementing press ESC to exit the script can be quite fun.
It is great for automating things.
Text Shortcuts on Mac is limited and unreliable, and I haven’t found a good 3rd party replacement yet.