from Hacker News

AutoHotKey V2 (Breaking Upgrade)

by numeromancer on 1/4/23, 5:06 PM with 120 comments

  • by function_seven on 1/4/23, 8:10 PM

    Somewhat timely. AHK is one of those utilities I absolutely cannot go without. I've been running it on all my Windows machines for 15 years now.

    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=34176791
  • by infogulch on 1/4/23, 11:10 PM

    I'm still reading through the changes ( https://www.autohotkey.com/docs/v2/v2-changes.htm ), but I like what I'm seeing so far. So many (many many) quirks and special cases are just gone now, I suspect users will find it much faster to learn and easier to avoid getting stuck on odd burrs on every corner.

    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.

  • by url00 on 1/4/23, 7:19 PM

    As someone who recently dove back into AHK, I must say v2 has been fantastic!

    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.

  • by otterpro on 1/4/23, 10:11 PM

    I've already ported my AHK script to v2, and it was mostly painless. It helps to use VS Code with the extension so that it can highlight what syntax would fail (mostly). Most of it was trivial like adding surrounding quote around `Send` function's param, as well as prepending `#HotIf` in front of WinActive(). As an added benefit, my dual function key is more reliable, ie sending capslock/control as escape or ctrl. (See last entry in https://www.autohotkey.com/boards/viewtopic.php?t=92738)
  • by bsnnkv on 1/4/23, 8:36 PM

    This is a bit of a PITA for me as most people use AHK to handle shortcuts for komorebi[1], which led to me generating an AHK library[2] to help people write their configs. Turns out every single line of that generated library (not to mention the entire sample config for newcomers) is now invalid syntax in v2.

    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...

  • by bluedino on 1/5/23, 1:40 AM

    Very useful program.

    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.

  • by rektide on 1/4/23, 5:21 PM

    The changes doc would be 10x more usef if it included more examples of the changes. https://www.autohotkey.com/docs/v2/v2-changes.htm

    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...

  • by mrandish on 1/4/23, 7:57 PM

    I struggle to get things done on any PC until I install my personal AHK script which remaps certain keyboard and mouse functions in ways which dramatically accelerate my productivity.
  • by nikanj on 1/4/23, 8:13 PM

    The bit about the anti-malware is sad. Does anyone remember a true positive from their AV? I can recall countless incidents caused by false positives, but can’t remember a single true positive.

    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.

  • by swader999 on 1/5/23, 4:56 AM

    Is it weird that I like Windows only because of AHK?
  • by BrandoElFollito on 1/4/23, 9:34 PM

    I like AHK very much but its scripting language is difficult to use of you do not use it often.

    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.

  • by JohnBerea on 1/5/23, 1:04 AM

    I love AutoHotKey but why do I have to learn a new language to use it? Why can't it use an established language like js or python?
  • by NelsonMinar on 1/5/23, 2:10 AM

    As everyone says AHK is phenomenal but the scripting language is pretty warty. I wonder if they considered using Lua or something instead of improving their custom language?
  • by slig on 1/4/23, 7:45 PM

    As someone who has been using Macs since 2006 and recently moved to Windows, I cannot recommend AHK enough.
  • by keybored on 1/4/23, 7:24 PM

    > > Nested Functions

    > 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.)

  • by FloatArtifact on 1/4/23, 11:29 PM

    Would a tool like Auto hotkey if it were implemented on Linux work with Wayland?
  • by LoveMortuus on 1/7/23, 1:03 PM

    Wow! This is exciting! While in my dreams I would still prefer a Rust alternative, sadly there isn't one.

    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.

  • by wolpoli on 1/5/23, 5:54 AM

    Here is a question for everyone: What would it takes for ChatGPT to provide support for the AutoHotKey V2 syntax? Is the manual sufficient? Would it also need a library of sample codes? Would it require StackOverflow posts?
  • by puffybuf on 1/4/23, 9:03 PM

    I first used AHK for macros in games. The scripts can even read pixels on the screen, play sounds or beep, execute programs, send mouse click/events. And of course send keyboard keys.

    It is great for automating things.

  • by tadamm on 1/10/23, 6:52 PM

    A lot off people dont understand which version to use. this video sheds some light on which is best for people https://www.youtube.com/watch?v=aMCP4hyzXwg
  • by csdvrx on 1/4/23, 8:14 PM

    AHK is what keeps me on Windows
  • by trts on 1/5/23, 5:34 AM

    AHK is the only reason I miss Windows (being on Mac presently). I had dozens of system-wide text expansions and optimizations. Also, a num lock toggle every 9 minutes to keep my screen awake.

    Text Shortcuts on Mac is limited and unreliable, and I haven’t found a good 3rd party replacement yet.

  • by maximus-decimus on 1/5/23, 7:39 PM

    I wonder if it will work with the IDE that someone had written in AHK V1. I can't remember what the website was, but it was a rather impressive IDE. All in one 10,000 lines file of course. Does AHK even support support packaging multiple files together?
  • by brrizna on 1/5/23, 5:42 PM

    I am a windows user, working more than 5 years as a backend developer and didn't use AHK ever. What do you use it for? I mean, can you give some examples of your scripts or tasks you perform with it?
  • by Kab1r on 1/5/23, 6:41 AM

    How long was v2 in beta? I remember writing a bunch of beta v2 scripts years ago
  • by LoveMortuus on 1/7/23, 1:06 PM

    While the change is probably quite needed, I hope it won't turn the years and years of help from forums irrelevant.
  • by just-tom on 1/5/23, 9:06 AM

    I was never able to make AHK to have 3 keys combinations, like Win+K+O to do something. Has anyone succeeded? Is it now possible on V2?
  • by bryanrasmussen on 1/4/23, 8:47 PM

    if the breaking upgrade thing is such a problem I guess it should be possible to run both versions side by side, although might require some registry tweaks?
  • by cool-RR on 1/4/23, 8:57 PM

    AHK has the distinction of being an absolutely indispensible tool and a horrendously terribly designed language. It's probably the worst-designed programming language I've ever seen. Whenever I'm frustarted with how slow and conservative Python development is, I remind myself that this is the main thing keeping us from reaching the same state as AHK.

    I hope that this upgrade will fix some of these problems. I'll probably take a few years before I upgrade my AHK scripts.

  • by numeromancer on 1/4/23, 5:06 PM

    I'm surprised no one has mentioned this; AHK broke compatibility with this upgrade. I tried upgrading autohotkey and it braked my scripts. It seems to have an auto-regress feature, which is nice. If someone knows where there is a comprehensive this-for-that upgrade guide, that would be nice; I didn't see such a thing on the site.