Hacker News new | past | comments | ask | show | jobs | submit login
AutoHotkey v2 Official Release Announcement (autohotkey.com)
255 points by majkinetor on Jan 28, 2023 | hide | past | favorite | 150 comments



I love Autohotkey because, in addition to its productivity benefits, it's a defensive tool against dark patterns imposed by user-hostile companies.

For example, I've been using it for years to enter my Runescape password [1] due to Jagex being clueless about security [2]

[1] https://reddit.com/r/runescape/comments/gxapao/how_to_paste_...

[2] https://www.troyhunt.com/the-cobra-effect-that-is-disabling/


My favorite use case for it is a hotkey to autofill my username and password for Zwift. Zwift is a cycling app that I'm only interacting with while I'm sitting on my bicycle (on a trainer indoor)

I have 0 patience for entering a password... I'm sitting there in spandex with a fan blowing in my face and I'm holding a wireless keyboard. Anything more than Ctrl+Alt+1 is too mcuh work


Runelite (https://runelite.net) enables you to do so, fwiw.


Is this a recent improvement? I'm pretty sure I had Runelite back when I came up with the AHK script, two or three years ago. Or maybe the issue came up while I was playing RS3? It's been a while so I don't remember the details!


Nope, but you do have to enable it in the settings last I checked. Not certain about RS3.


Ah I see, good to know! Thank you for that. I searched the web and apparently it's part of the "Login Screen" plugin https://runelite.net/blog/show/2018-11-22-1.5.1-Release/


I work in a large enterprise who's idea of single sign on is you use the same dialog for everything and have to type your username and password every time. They are fairly strict about saving passwords so I use a hot key for my username that also logs the time and date of usage


I'm surprised they're not strict about running AutoHotKey itself.


Strangely enough someone managed to get it installed on the internal app store. If I could find out who it was I'd buy them a beer or eight!



That's a browser extension, so it can help with websites but not with Runescape, unless I'm missing something?


You can use KeePass for that too, you can even customize the script to press (password)(enter) with a single shortcut.


Note: There are a lot of implementations of KeePass that surpass the original in quality.

KeePassXC is likely the one that's best for most people who wish to go down the standalone application route: https://keepassxc.org/docs/#faq-keepassx

Since quite a while ago now, Tails switched from KeePassX to KeePassXC: https://tails.boum.org/doc/encryption_and_privacy/manage_pas...

So if you're still on KeePass, KeePass2, or KeePassX - consider upgrading to KeePassXC.


Another vote for KeepassXC. An amazing fork.


Oh yes, KeepPassXC it's a nice upgrade.

The main reason why I recommend regular Keepass, it's because it's usually whitelisted in company owned equipments (with something like Microsoft Endpoint Software Center), so even if you don't have admin or permission to install your own software, regular Keepass it's still available.


Yeah, being able to use it through type passwords in the terminal, in a DB GUI, even a VDI session is pretty neat.

I wanted to switch to one with better mobile experience, but the desktop experience in KeepassXC does make it worthwhile


you only have to login to jagex launcher once to start runescape without a password btw. you can also manage alts with it.


I ended up using AHK for komorebi[1] because I was still new to Windows when I started writing it and I didn't wanna have to write a tiling window manager AND a hotkey daemon. I even ended up generating a nice little AHK library to wrap around CLI commands that sent socket messages to the window manager to make it easier to write a configuration.

Ultimately the syntax changes make it impossible to fully reproduce the same library for AHKv2, which is being installed by default on all mainstream package managers now.

I ended up biting the bullet and making my own hotkey daemon[2] for use with komorebi based on skhd[3] and I haven't looked back since. This will be the "blessed" hotkey daemon recommended for use in the next release of komorebi.

I'm still using AHK (v1) for the stuff that it's good at (and there is a lot of stuff that it's good at!), but ultimately I've found that it's not the right tool as a hotkey daemon for a socket-based tiling window manager (or just generally, for triggering CLI commands).

[1]: https://github.com/LGUG2Z/komorebi

[2]: https://github.com/LGUG2Z/whkd

[3]: https://github.com/koekeishiya/skhd


Can't you just right click on you script and pick "compile" or something similar to pack the v1 interpreter with your code? I remember a functionality like that existing.


I don't think it's quite that simple with this use case[1][2], but I'm happy to be proven wrong!

[1]: https://github.com/LGUG2Z/komorebi/blob/master/derive-ahk/sr...

[2]: https://github.com/LGUG2Z/komorebi/blob/master/komorebic.lib...


I just downloaded v2, purely by incident (haven’t used AHK for some time) but there is now official support for compile-to-exe. No idea how good it is, I’ve only used AHK for one-offs, short term projects, etc.


That's in v1 too.


Wished that you chose toml/yaml/json/etc. for the hotkey daemon. One thing I don't like about new custom DSLs is that they usually don't come with a syntax highlighter and auto-formatter.

Also, will you also get rid of the *.generated.ahk stuff in the next release? It would be far more ergonomic if komorebi can just read and apply the yaml config directly.


I'm sorry you got downvoted for this comment, for what it's worth I tried voting it back up.

The DSL is largely "borrowed" (stolen) from skhd, which has been around for a long time, so most existing shkd-syntax-compatible tools should(*) work, but I think I will take the time to also write tools specifically for whkd in the future based on this comment.

TOML/YAML/JSON are imo even worse than AHK for configuring hotkeys that trigger potentially complex CLI commands. There always comes a point where the user is stuffing an entire sh script into a string and suffering in escape sequence hell.

You can take a look at the feature/whkd branch on the komorebi repo for an idea of how this will look going forward.

Backwards-compatibility with all the AHKv1 generated libraries will remain for users who don't want to move to AHKv2 or whkd, and a new PowerShell generation target will complement the AHKv1 generation targets, finally bringing komorebi full-circle back to the bspwmrc/yabairc model of configuration using a script in the configured system shell (which also launches the hotkey daemon).

As for moving away from the "bspwm architecture"[1] (I think this is what you meant by "read and apply the yaml config directly?) - this will never happen. I've written before about how I feel that the bspwm architecture is the endgame for tiling window managers, and my thoughts on this topic haven't changed.

The komorebi license is pretty permissive so anyone is free to fork it and change it if they dislike the bspwm architecture that much.

[1]: https://github.com/baskerville/bspwm#description


Thanks for creating komorebi.

I had tried to set it up a while ago but had to give up. Configuration was a bit arcane! I wonder if other TWM are like that as well. I just wanted to upgrade from PowerToy’s zone manager, but the step from that to komorebi was very steep.

Maybe one day there’s a more idiot-proof approach to komorebi! ;)


I'll start working on a full setup video to post on YouTube once I have finished packaging and getting whkd onto the common package managers! Keep an eye out in the next month or so.


AHK allows me to program my own eclectic mashup of emacs and vim and put it in every single app on my windows machine including VS, VS Code, Chrome, Word, outlook, everything! My brain is broken without it, it is a godsend.

For the curious, like emacs, my "command mode" is whether or not I'm holding the alt key. Like vim, my command mode navigation is based on the relative positions of different keys. I know that vim uses jkl; for the arrows. I think it is easier to use "ijkl" in much the same way you would use "wasd". But based on position, home, end, page up, page down are included as well as delete. My hands never leave the home row. Technically "alt+j" will map to "ctrl+left" so that it moves my cursor an entire word and not a single character.

quick and dirty annotated map. https://drive.google.com/file/d/1VWXMoh2pN7WrwC5Y2p0BNoYGOzt...


Hah, are you me?

> Alt/Capslock + IJKL is a universal way to get arrowkeys https://news.ycombinator.com/item?id=29162132

I have similar keys to yours, but U and O are left/right four times, and 8 and , are up/down four times. Could make it more, I just know that 3 is to small.

I also use ahk as my window manager, which is essential for working on a 4k 100% scale screen: https://www.autohotkey.com/board/topic/79338-simple-window-p...

I also also have a hotkey for nearly every program I use on a daily basis. Win 0-9 are used of course, but Caps+F1-F12 are also used, and I've recently added Insert+letter keys to my collection thanks to my new fancy QMK keyboard. My goal is to never alt tab again :)

I also also also have an emacs/whichkey kinda thing, which does exactly what you think:

    CapsLock & E::WhichKeyMenu()
    WhichKeyMenu() {
      CoordMode, Menu, Screen
      Menu, WhichKeyMenu, Add, &C Code, Code
      Menu, WhichKeyMenu, Add, &D Desktop, Desktop
      Menu, WhichKeyMenu, Show, % A_ScreenWidth/2, % A_ScreenHeight/2
      return
    
      Code:
        run, explorer.exe C:\code
      return
    
      Desktop:
        run, explorer.exe C:\Users\dharm\Desktop
      return
    
    }
This is, of course, extensible to any AHK command, not just running explorer. Also means I don't have to memorize every goddamn shortcut. Only weird thing is that I have to exit out of it with Alt. Escape doesn't work and I dunno why.


> I know that vim uses jkl; for the arrows.

No, it uses hjkl. But of course the spirit of Vim and Emacs is that you can customise these things.

Incidentally, I have quite a similar ‘Vim everywhere’ map, though I use CapsLock rather than Alt to change modes.


I have a movement layer on my keyboard that uses ijkl for arrows and pgup/dn, esc and enter when I hold my thumb on a thumb function key.

You should look into QMK and ZMK-based keyboards and you can set up all kinds of crazy stuff. Sounds like you'd like it.


Autohotkey is the only windows thing I miss on Linux.

And it seems impossible to even discuss desktop automation with contemporary Linux DE people, they just glaze over. "Like, why would you want apps to be able to control other apps, that sounds dangerous! We definitely want to protect you from that in Wayland.... Oh, what's that? You are a large consultancy that uses time tracking apps to help with billable hours? I guess you have to change your business model"


Check out https://bitbucket.org/mfeemster/keysharp/ and https://github.com/phil294/AHK_X11, two attempts at reimplementing AHK on Linux. The former is v2 but not usable yet, the latter is by me, v1 "classic" and somewhat incomplete.


Many thanks. How do they compare with autokey? I haven't tried it properly, but it gets mentioned a lot. https://github.com/autokey/autokey


I haven't used AutoKey personally, but it's quite capable and generally "just" a Python library that also happens to ship with its own optional editor (https://autokey.github.io/autokey/_images/AutoKey_Scripting....).

Keysharp / AHK_X11 on the other hand ship their own runtimes that will be / are compatible with the actual programming language AutoHotkey v2 / v1 and thus cannot be used in conjunction with other languages, apart from shell invocation. For a detailed feature comparison with AutoKey you will have to research this yourself, but there's at least one feature which is exclusive to AHK_X11 right now, and that is accessibility-related commands such as ControlClick or WinGetText.


AHH that's very interesting and useful. I'll definitely check them out.


Same. I also really miss Hammerspoon and Karabiner from macOS. Just being able to remap custom keyboard shortcuts for specific applications was so nice. On Linux, most things are customizable enough that I can get by without it, but it feels like a major missing piece.


I used AutoHotkey to send keystrokes as media commands to an mpv window (if one is open somewhere in the background -- so I don't have to alt-tab from games) and as those literal keystrokes to the rest of the system. On Linux, I do that with `xdotool`. But that's an X11 thing; on Wayland, yeah, there's probably no `xdotool` replacement yet. :p


ydotool and dotool are subsets of replacements, but for me the missing part on Wayland is getting the cursor position, which is a game of hot potato - Wayland says it's the compositor's job, compositors say it's the app's job, so the capture app has to draw a temporary full-screen overlay to register a cursor position on it.

It's like asking someone "where am I" and them setting off a contraption that drops a bowling ball on some dominoes that launches a parakeet into a blanket covering a street sign to knock it off and show you. It's all very clever and allegedly safer than just saying it out loud, but also stupid.


Yeah this is definitely missing on Linux. I do agree with the sentiment that password managers shouldn't use this kind of API (they should use something designed to transfer secrets between processes instead!). But the automation scenario is still perfectly valid. Something like selenium-for-desktop would be superb.


Its possible - atleast on xorg, but why not write scripts in your favourite language to do the same automation instead of using a third party app ?


I think it makes a big difference having something that is domain focused. I remember being new to it, I'd open the windows menu > Autohotkey > and it had two things, I think, the manual and Windows Spy. I think that manual is one of the best I've read and easily made up for the jankyness of the syntax. And the manual instructs you to open windows spy and click anywhere on a window that you are interested in and it tells you everything you could possibly need to know to read and interface with any window control. And if you get stuck, they had an awesome forum full of people working on the same types of problems. And of course you could also embed python, c or c# (probably others, too) or you could embed autohotkey scripts in python, and so on. So, while I know that most automation can be done (if using X11) on Linux, the friction is way higher. And it's a shame because when it comes to non-gui automation GNU/Linux kills it.


I miss everything search engine too. Nothing similar exists.

Was missing total commander but now that is solved with double commander.


Have you checked fsearch? https://github.com/cboxdoerfer/fsearch It got very good in the last 1-2 years and while ext4 fs don't support a file index like NTFS does, fsearch is still very fast, caches its results, offers similar features etc.


Now that ntfs3 has landed in the kernel 6, I wonder if locate/updatedb could leverage this file index? (I do plan a full-ntfs3 Arch or Linux install soon to experiment with such weird ideas :)


No. Looks promissing, thanks for the info!


Ui.Vision dekstop automation is cross-platform works on Linux and macOS (and Windows). It is not exactly the same, though.


People are sleeping on Windows Power Automate too


You are a large consultancy but too broke to pay anyone to write software? Yeah, then changing your business model is probably long overdue.


I saw there's a python library that just lets you write autohotkey scripts in actual python code. I'd rather try that if I was going to rewrite my v1 scripts. AHK is awesome but the scripting language was never good. The new one looks like it has some better syntax, but native python support would be a much better solution for a lot of people.


Why? The AHK python library isn't going to be so cleanly abstracted so that a different automation engine (eg hammerspoon w/ lua on macOS) can be plugged in, so the code is always going up be tightly coupled to AHK, and Python support is likely to be second-class to support for its own language. So other than some obsessive need to standardize on a single language which will never be won, what does Python buy?


Python buys into pypi, which has a 6-digit number of packages, e.g opencv can read your screen to find buttons, etc.


I realise you are giving opencv as an example of why having Python to AHK would be desirable, but for anyone wanting to read GUI elements like buttons there is ImageSearch[1]:

Also, to make it even easier to generate AHK scripts to automate button clicks, clicker games, or boring tasks requiring the keyboard and mouse, you can generate an image recognition AHK script quite easily using Pulover's Macro Creator[2]. Even someone with minimal knowledge of scripting can use it to automate Windows.

Even without Python, AHK is amazing. It gets a lot of undeserved flak from advanced users, undeservedly so in my opinion.

[1] https://www.autohotkey.com/docs/v1/lib/ImageSearch.htm

[2] https://www.macrocreator.com/


No flak intended, AHK is much easier for non-programmers and can do more than you’d think. I’ve show a few people how to rig up an automation in a few minutes. The bar to entry is much lower than for any of the «serious» languages out there. AHK is amazing!


AHK was my introduction to programming. I’m a bad speller and I wanted certain common errors I made corrected automatically. I had a very basic but fully functional program in literally minutes. I spent the next few days adding features, and it was amazing to me how someone with zero programming experience could translate my thoughts to code.

This is what makes AHK special, I’ve never seen anything that can abstract away everything between the code and a fully functional program so well, making it an ideal learning language, especially for children and others with very little technical experience.

I don’t use AHK too much anymore as it’s limited to windows, which is a real shame as I’ve never seen anything better for quickly creating UI automations and tiny programs extremely quickly.


Syntax


I really don't see how AHK's script language is somehow not intuitive or simple enough. The syntax is pretty easy to grasp.

You have all the tools "natively" to even pick positions on windows, its pretty extensive too.


I write AHK scripts like once or twice and then forget about it. I can't remember the sytax so I'm constantly googling. I'd rather have it in a language I already know well. Also as a long time programmer who knows a lot of languages, the AHK syntax (at least in V1) was anything but intuitive. It had very weird conventions.


I find the syntax easy and the documentation (of v1, not enough experience with v2) is easily accessible and of high quality. V2 solves some inconsistencies in the syntax and language but at the cost of being compatible with v1. I've been able to port my v1 scripts to v2, and I'm a lousy programmer.


Fair enough


The syntax is a nightmare. I honestly never understood why they made it so complicated.

Should I use a brace? On the same line or on a new one? How to pass parameters, with or without paranthesis? Should I use ::?

There are many such issues.

I love AHK but every time I wrote a script or is trial and error to discover the proper syntax.


In today's polyglot software development world, one real difference between someone who's a programmer and a software developer is fluency in multiple languages. That might come off better when it's Python and GoLang/C++/Rust instead of AHK, but realistically, every domain has their own DSLs.

A competent software developer should be able to check their ego and use curly brackets instead of PEP 8 4 spaces if that is what the situation demands. And also be able to resist the urge to reformat an entire Python codebase that was written to 2 spaces.


Who's using AHK as a developer? I use it a a hobbyist. I don't want to have to remember a proprietary useless language syntax.


Coming from an ahk user circa 2010, I have never been able to wrap my head around pythons insistence on indentation. Ahk let's me type whatever however and it just works.


Honest question, why? If you properly format your code then it's indented anyway so Python is basically just replacing `{` with `:` and then not having a `}`. Python is the least problematic of all the languages enforcing some style things. Go insisting on Google's stupid styleguide is just dumb, Lisp having the parentheses on the wrong positions and ignoring the fact that there is more than one bracket type available is dumb, all the languages with `END` blocks are dumb because `{ ... }` is much shorter and cleaner, ... . Python has its annoyances too but indentation really isn't a problem - it's there already anyway.


as i said, i am not a dev so i never learned "convention"....

AHK let me scrap whatever script from internet or i could come up, throw them in notepad and it would work.... now, python makes you "properly indent" which coming from AHK makes my head explode

https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2F...

this is a good example. AHK would read this normally but no, python sees whitespace and wants to "use that"....

https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2F...

this would never happen on AHK so it makes me mad.

part of the reason why i have never gotten hold of python while i can whip up an AHK script in my mind


Fair enough, I can see that this is something which can easily throw you off if it isn't part of your normal workflow.


I wrote MicroKeys[1] out of a similar frustration. Granted, I never got past the POC stage, so it's not as feature rich as AHK, but it solved a very specific itch I had. I debate if I should flesh it out further, or try using AHK again.

[1] https://github.com/seligman/microkeys


I've been using SikuliX [1] instead of AHK for a while now, only downside is that it uses jython so it's stuck on 2.7, but I don't use it for anything complicated enough that it really matters. Also I mainly use it for long running, rarely used automation, so I'm not sure how it would compare in terms of responsiveness for tasks like text expansion.

Also I did a quick search and I assume this [2] is the library you mentioned?

[1] https://github.com/RaiMan/SikuliX1

[2] https://pypi.org/project/ahk/


Pyautogui? https://github.com/asweigart/pyautogui

That one is also cross-platform, if that’s useful to you.


That doesn't seem to do any of the hotkey, hotstring etc. stuff that is AutoHotKey's main purpose.


In case you're open to something for JS instead of Python, my life has been much better since I switched from AHK to nutjs for my own automation scripts: https://nutjs.dev/

A real programming language, and support for multiple platforms!


Alternatively if you're into dotnet, FlaUI is amazing for automation and gives you a sane environment. I moved to it when I couldn't deal with AutoIT scripts anymore and it's everything I needed. https://github.com/FlaUI/FlaUI


I recently updated my scripts to work with ahkv2. https://github.com/EBADBEEF/ahkv2-scripts

Some things I'm proud of here:

  - easy debug console (https://github.com/EBADBEEF/ahkv2-scripts/blob/main/Autostart.ahk#L4)
  - compose keys (to type keys like "¿ é ü" easily). Includes libX11 key database parser
  - window move and resize with mouse
I love AutoHotkey's documentation. It is an old school windows help file (chm) and it works really well. All my scripts run in an AutoHotKey process that takes less than 2MB of ram and provide great value to me.


Old school is .hlp not .chm


At that point it probably "ye olde skool"


Autohotkey is awesome and special, and everybody on Windows should learn it. There is no such thing on any other OS.

v2 syntax and features are so much better. It was basically in development for a decade and AHK itself more then 20 years.


macOS has AppleScript that does the same thing, and it’s built into the OS. https://developer.apple.com/library/archive/documentation/Ap...


ApppleScript was an amazing foundational part of what made the Mac so great, but unfortunately Sal Soghoian was pushed out of Apple, the Mac automation team ended, and the new future of Mac automation is an iOS application. It’s by no means dead, but it’s absolutely a zombie at this point, shuffling along until Apple inevitably depreciates it out of it’s usefulness.

I actually think AHK has the better model here. It takes low level windows functions and presents them in a fairly simple and low friction way. MS could never end AHK without also breaking an unfathomable number of other applications.



Looks like a feature that is obsolete and in the process of being phased out, considering that documentation for it has been archived.


> does the same thing

So how to you create custom keyboard shortcuts with it?


> There is no such thing on any other OS.

I thought the Mac comparable was Keyboard Maestro. Are the two that different (asks someone who hasn't used Windows since the '90s)?

https://www.keyboardmaestro.com


Another utility along those lines for macOS is Hammerspoon:

https://www.hammerspoon.org/


I use Karabiner Elements and Hammerspoon. Hammerspoon scripts are written in LUA, Karabiner Elements has a large repository of useful scripts.

On Linux I use Wayland but there are several ways to tackle that, involving /dev/uinput. For example there's Python bindings for that and several Rust apps to achieve it. In the end I use ydotool and kbct.

On Android I use MacroDroid.

You can also do some neat stuff with Selenium.


On mac I use goku[1] to define custom key bindings for karabiner elements. The ux feels much better than autohotkey, and I wish I had something similar on linux or windows.

[1]https://github.com/yqrashawn/GokuRakuJoudo


Maestro is more like a Macro Recorder while AutoHotkey is a programming language for automation.

Also AHK community is huge.


> AutoHotkey is a programming language for automation

That's sort of what AppleScript is supposed to be on MacOS I thought? I'm not familiar enough with either AutoHotKey or AppleScript to be able to compare them though


Keyboard Maestro is not just a Macro Recorder. It can control most of the Mac interface and most applications. You can start using it as a recorder but when you learn to to incorporate applescripts and other tricks, it can manipulate the entire Mac experience. I would be lost without it.


Autokey on Linux?


There is no such thing, at least in the mainstream. There are surogates, more or less capable, however nothing close to AHK

1. xdotool

2. sikuli

3. AHK_X11



AHK is way more mature then autokey has huge community and big amount of ready to use scripts and autoamtion libraries.


As someone who has always been 'AHK-curious' but never got around to using it, ChatGPT has been an amazing at helping me write scripts and custom hotkeys

The productivity gains are very real


Thanks for this idea. My main frustration with auto hotkey has always been that I only need to use it once in a long while - just infrequently enough that I forget what I've learned and eternally suck at it.


The scripting language for version 1 was pretty terrible but having messed with version 2 for a while now I'd say it's pretty decent.


I have a not-too-long list of keybinds that's currently on v1. Would you mind taking a look and letting me know if anything's not v2 compatible? [0] I don't think anything is that complicated, there's a loop or two although tbh those were more one-time-use things I haven't bothered to get rid of, in part so I have the syntax there as a reference in case I need it again. I do remember reading something about SetTitleMatchMode being deprecated though, but I'm not sure if that includes RegEx.

[0] https://github.com/RheingoldRiver/misc_settings/blob/master/...


I'm not an expert, but these are basically the changes I would see that need to happen:

All of the places where you use commands no longer need a preceding comma:

    Run, Calc.exe
This is now just:

    Run "Calc.exe"
Similarly, all areas where you use strings now need to be quoted:

    Send, https://discord.gg/6SNQ4c6
Will now have to be:

    Send "https://discord.gg/6SNQ4c6"
AFAIK the area where you use "blocks" of code like this:

    ^!+x::
        ... stuff ...
Will now have to be enclosed in curly braces:

    ^!+x:: {
        ... stuff ...
    }
Where you use special constant/strings for the "Send" command now needs to use regular strings:

    Send "+{Tab}+{Tab} {Space} {Esc}"
Where you do an "if" condition like this:

    IfWinNotExist ahk_class MozillaWindowClass
        return
Will have to turn into something like:

    if (not WinExist("ahk_class MozillaWindowClass")) {
        return
    }
A full list of the differences is available at https://www.autohotkey.com/docs/v2/v2-changes.htm


oh wow, that's a pretty comprehensive set of changes, thanks for the reply! I'll procrastinate on this a bit then, it looks like it'll be closer to an hour than five minutes, although not too bad simply because it's not that big a file.


Yes I was busy for an hour (I switched a month or so ago) with my 1k script and I am a lousy programmer. However every error was easy to debug. The documentation was ace (probably even better now?), and when I got stuck regardless a couple of search engine queries got me covered.


Or you could ask ChatGPT to rewrite your scripts, maybe just give them the rules above.


I tried. I really, really, really tried. It......can't do it. There's a few rules OP left out (or I guess, glossed over as a generalization), like IfWinActive now needs to enclose its stuff in braces and that's just too much for it. I put its first attempt as well as its last two here: https://github.com/RheingoldRiver/misc_settings/issues/3

After I read the changes it told me it made (I always do something like this to get it to check its own work) I was like "hm this is sus as fuck" so I had it redo it several times and then yeah just....gave up.

Good idea though, and I did learn a bunch about the syntax so when I go to do it myself it'll be easier. I wonder if some of what OP said was determined later than GhatGPT's cutoff date, although I don't think so - I remember even back when I set up these hotkeys 2.0 was in an early beta and I was like uhhhhhh no there's almost 0 docs on this, but I thought I might regret it one day; I don't, though, there were 0 docs back then, it was the right call.


You could just run it through a converter [0] and see if anything breaks

[0] https://github.com/mmikeww/AHK-v2-script-converter


Funny, just yesterday I was working on automating my linux-desktop, and for specific capabilities, I only found solutions for AHK on Windows, not the normal tooling on Linux. And it seems the limitation of capabilities are for security reasons, like for example, the inability to send Keyboard-inputs to an unfocused window. How is this with Windows and AHK? Has Microsoft also shutting down abilities and crippling AHK in the last years? Or how is something like AHK still working find and powerful after such a long time?


>send Keyboard-inputs to an unfocused window

I'm pretty sure AHK can direct key presses based on process id or window id.


I haven't had a single script fail yet. Haven't updated most in 5 years.


It is great. I honestly used to use it to automate pieces of work in a software that had terrible bulk tools, but now that I’m more on the management side I heavily use it to substitute words/acronyms. I have it expand all my acronyms for docs. If I put metrics on it I’m assuming it’s most heavy lift for me is fixing MS autocorrect for VLAN and IT.

Unfortunately (or fortunately) I ended up getting into other scripting tools/languages to figure out how to work around certain programming environments.


AutoHotkey was a lifesaver for me when I used to work on Windows. Universal CapsLock VIM movement keys, app-specific shortcuts, clipboard manipulation, text expansion, autocorrect. It really is an amazing tool. For mac, I've been able to cobble together a mix of karabiner, phoenix, and espanso to do all of what just AutoHotkey could do.

Coincidentally, my AHK config was my first open source repo on GitHub. I'm glad to see it moving forward.


If anyone has combined the power of AHK with a physical device like a StreamDeck it would be great to see examples.

In general too is there a gallery of great AHK use cases that we can emulate or get inspiration from?


I recently got a streamdeck and followed this thread to get some AHK scripts mapped to SD buttons. https://www.autohotkey.com/boards/viewtopic.php?t=53318

Also found several resources on github. Will dig up the links when I get a chance.


What are some use cases where having AHK scripts would help? On the same note, can anyone share some existing list of scripts and their functions which helped make their lives easier?


You can complain about ethics on this one but, for awhile, I was using an AHK script to autoclick through an aggressive "Your trial is over, Buy now please!" style dialog that randomized the position of the exit button for the box. The software would let you continue using it if you clicked through though.

Every ~200ms the script scanned a small portion of the screen where the exit button might appear in and if the script found the button then it would close the dialogue box for me.


Here's one of mine: JKLmouse.

This was originally a program I wrote in C for my own use on my ThinkPads some 20 years ago. It turns various keys into mouse movements whenever a mouse button or the Caps Lock key is held down, so you can use the TrackPoint for coarse movement and then seamlessly move the mouse pointer pixel by pixel with the keyboard.

It's a bit like the MouseKeys that is built into Windows for keyboards with numeric pads, but designed for laptop keyboards that don't have that.

When I discovered AutoHotkey, I rewrote JKLmouse using it, and it made it so much better. The code was simpler, and I could make a change and reload the AHK script without having to reboot. I think it is a pretty nice example of some readable and maintainable AHK code.

You can find it here: https://www.jklmouse.com/

There is an installer, but I haven't kept it up to date. Instead I recommend installing AutoHotkey directly and getting jklmouse.ahk from GitHub and using it as an AHK script.

Now I have to see about updating the script to work with AutoHotkey V2!


I bind ctrl+space to make the current window stay on top of others. Sometimes it is a commandline or file explorer or notepad that I want to keep visible while I click something else behind it, without rearranging the windows side-by-side.


I like to prefix files with a YYMMDD date, so I made a script to do that when I press a hot key, and also send a text to my wife to bring me a cup of coffee.


So on days with more files you drink more coffee? For me personally the files pretty fast would be the limit, else I get really jittery…


Do you mind sharing that?


Bind Windows-B to type the date in the form 2023-01-30:

  #B::
   Send %A_YYYY%-%A_MM%-%A_DD%
   return


Back when I played Minecraft, I wrote one I was pretty pleased with:

If you have a stack of items, you can pick up half of them by right-clicking on it, which is very convenient when you're dividing out a stack on the crafting grid to make many copies of a recipe that needs that item in 2 or 4 slots; but for some recipes, you need to put the same item in 3 or 6 slots, and there's no built-in way to divide a stack into thirds.

So I made an AHK script that, when I held down a key, would

- pick up half of the items in the stack I'm pointing at (right-click) - move the mouse one inventory space to the right - put them down (left-click) - pick up half of them again - move back one inventory space left - put them down, adding them back to the original stack - and repeat

and it would only stop after one of the "pick up" steps; so, after a few iterations, you'd be left with the stack divided into equal thirds, two in your inventory & one on the mouse.

Eg, starting with a stack of 60, it goes 30/30, 45/15, 22/38, 41/19, 20/40, 40/20, 20/40, 40/20... then release the key, and you've got three stacks of 20.


If I remember right: Last time I played Minecraft you took the whole stack of materials and painted (left drag) over the grid where you want the items. It would share up the stack evenly over all the grid items no matter how many you painted. Very easy to make stairs for example. I think there is an even easier way now but haven't played for a couple of versions.


I have an adjacent, simple scripting story.

Battlefield 2042 recently had an XP glitch where you could go into a server with BF3 settings, throw ammo to a teammate and get XP for the resupply. Naturally there were several servers dedicated to this with 128/128 players and everyone on one team all standing at one objective.

Rather than actually play the game to level up and get the weapons/gadgets I wanted or even play this accelerated XP mini game, I wrote an ahk script to automate the equipping and dropping of the ammo crate so that I could do other things.

I only had to let it run for a few hours before I was max level, and the 10 minutes of scripting gave me the benefit for something I wouldn’t otherwise subject myself to.


I had to type an incrementing number over an over. I wrote a scrip so that one key would type a variable and then increment it and another key to decrement if I messed up. Saved me a lot of time.


I have a laptop whose keyboard is physically a QWERTY, but I configured to use (the Belgian variant of) AZERTY. There is one physical key missing on QWERTY compared to AZERTY, so there are 3 characters I cannot type normally, and not rare ones: < > \

I created an AHK script that binds other, convenient key combinations to those characters. Now I can type them.


I've used it with video games to convert actions which require you to hold a button (e.g., running, chopping wood) into actions you toggle on or off with a single button press.

I've also used it to quickly enter lots of data into a native application that only supported adding one item at a time.


I've done some scripting for a very annoying enterprisy software in a medical environment. Think "repeat the action for those 100 patients" without spending hours clicking around. It started in AutoIT and migrated to FlaUI, but probably could've started in AHK as well.


AHK brings back memories. The campus I was working at had the dorm network saturated by Sasser and variants. Networking turned off the dorm network. I used AHK to automate Windows patch installers, installing Norton Corporate AV and grabbing the MAC address to disinfect Sasser from dorm computers. Over the course of a weekend or two everyone in the dorm had to have the hotfix & AV installed or show us their MacOS or Linux box and provide the MAC address to get back on the network.


I use AutoHotkey every day but find it’s not very reliable. I have one script that checks if the current window is File Explorer and if it is, gets the currently selected file or directory and does something with that. If I have more than one tab open, it will usually (but not always) give me the selected item from a different tab. Reloading the script fixes the issue sometimes.


It looks like Explorer tabs are a very recent addition to W11, so perhaps it isn't fully supported by AH1?

Unless by 'tabs' you mean 'instances' or 'windows'?


It works sometimes and when it doesn’t, reloading the script will sometimes fix the problem.

I just asked ChatGPT how to get the currently selected file in the current tab of File Explorer in AutoHotkey and it spit out code that works quite a bit differently than mine. Later today I’m going to figure out what it’s suggesting and see if a different approach is needed.

——-

The ChatGPT code is nonsense that looks like AutoHotkey code.


Ahaha oh dear, well at least you tried.


I ended up uninstalling the older version of AHK that I had installed and updated to v2 and rewrote the script using a slightly different (and simpler) method of getting the currently selected item in the window. So far today it’s working…


Tabs are new in the Windows Explorer, right? Did you update your script to reflect that?


I’ll look at it again, but it seems if that were the problem then reloading the script wouldn’t change anything.


I always preferred AutoIt over AutoHotkey. There is something with syntax of AutoHotkey I can stand.


AutoiIt community is hostile. It is also way slower, larger, hungrier. Now it has worst syntax too.


Hostile, really?

I was around the forums a decade ago and it was a wonderful place.


Yeah, its not hard to find that info all around. Maybe you were lucky.

More importantly its considerably larger and slower.


I have many fond memories of making bots for games. Like fishing in World of Warcraft. I haven't used it for like 5 years, but I should check it out again - maybe not for games this time but maybe for auto-posting on Social Media for my company


I see here are the masters of ahk! Is there a smart way to mark/record from a specific moment till "done" and just reply it 1/n times? I tried many macro tools but none of them was "just easy" to use.


Can you expand on “from a specific moment till done” and possibly provide an example? What’s the exit condition? Time? A ui change? Seems like you could write a do_macro function and bind a key to loop it till “done” but I may be misunderstanding


Oh yes of course, thanks for the follow up! I work in many different applications therefore I can't create fixed automations for the major part, but many times I come across tasks I need to do N times with ui elements always on the same spot. Think of it like the very same website but in a different context (build, commit, server, ...). I want to start a macro recording, do my stuff and stop the recording, then start the playback N times like shift-F11-13 where 13 is the number of loops. All that should be ui hidden and always be on the watch for my keystrokes to start recording/playback.


Thanks for the extra details, I think I understand what you’re looking for.

Have you looked into something like this[1] for generating the macro as an ahk file? Full disclosure: I have not used it, but it seems like what you’re looking for. If you find that it suits your needs, I’d use that to record the macro and then wrap it in a loop from 1..N where N is based on the Fn key you press. That should do the trick unless I’m misunderstanding.

I wish I could be of more help, but this repo seems like a decent starting point for your use case.

Apologies if the formatting is poor as I am on mobile.

[1] https://github.com/adegard/AHK_SCRIPTS


One great use of AHK for me was the remapping of the keypad when it is not in number mode. I have all my important shortcuts there: Bitwarden password fill-in, starting Logseq for notes, a launcher for programs, ...

It is really a time saver.


Ah yes, the world absolutely needed another experiment whether idealized syntactic purity is more important than a 20+ years library of working code.


What changes and benefits, besides removing the dual syntax, does V2 bring? It's not clear by the announcement post.


When I switched to a Mac, AutoHotkey is what I missed the most.

My muscle memory still wants me to middle-click in a Finder window.


Keyboard Maestro is your friend here.


long time ago I used this thing to build a bot in whatnot mmorpg. may not have been pretty code but the important thing is - it was functional.


[2013]


No, the author is "joedf Posts: 8656 Joined: 29 Sep 2013", this post is "22 Jan 2023, 11:52".


Oh! I'm starting to forget these old forum designs I guess.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: