[HN Gopher] Show HN: AutoHotkey for Linux
___________________________________________________________________
Show HN: AutoHotkey for Linux
Hello HN, this is the first functional reimplementation of
AutoHotkey [1] for Unix-like systems, as far as I am aware. Half
the commands are still missing, but everything important is done,
as I have worked a lot on it over the past two months. Converting
scripts into stand alone binaries is also supported. Hope this will
find some adoption eventually. :-) - This implementation focuses on
v1.0-like classic syntax from 2004 (!). This is a significant
_subset_ of the popular current v1.1 syntax from Windows (AHK_L).
The reason this does not (yet?) target the full Windows spec is how
complex it is. Notably, there 's also another ongoing project which
targets v2 called KeySharp [2]. If you are not aware of what AHK
is, it is an easy but capable scripting language for automation and
Hotkeys, and all sorts of visual things like GUIs. If you want to
learn more, there plenty of info on the repo, the docs html, and
there's an active AHK Discord too, and I am personally also
checking the forums and HN of course. [1]
https://www.autohotkey.com/ [2]
https://bitbucket.org/mfeemster/keysharp/
Author : phil294
Score : 199 points
Date : 2022-08-30 19:26 UTC (3 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| neverrroot wrote:
| One of the only things I truly missed under Linux. Much can be
| solved using various tools such es AutoKey, XbindKeys+Guile etc.
| but nothing comes close to what AHK was capable of under Windows.
| jrm4 wrote:
| Advantages over xbindkeys?
| squeaky-clean wrote:
| I don't use xbindkeys so maybe my impression is wrong, but AHK
| is far more powerful. You can incorporate state into your
| scripts, or read things from the screen and act conditially on
| it (though the repo says WindowSpy is unsupported. I think
| that's what allowed screen-reading).
|
| You can compile it into a binary with no dependencies, so you
| can easily bring your script to other computers or share it.
| You can create a GUI to run commands rather than binding them
| to key patterns.
|
| I used to use it in World of Warcraft to do things like have my
| character's entire skill rotation on one key (e.g. just keep
| pressing "1" and AHK will handle pressing the next "real" key
| for the sequence. Hit another key and I can reset the sequence
| early). And to automatically tatget myself and cast a heal when
| my health goes below 50%, which was done by polling a certain
| pixel on the screen for a specific value of red.
| A4ET8a8uTh0 wrote:
| Absolute level of awesome ( even though some companies do
| clamp down hard on features like these for a variety of
| reasons ). Have you tried offering those scripts to players?
| I am more than certain that most MMOs would have loved to use
| them.
| squeaky-clean wrote:
| Sorry :p this was way-way back in vanilla days, before I
| took backing up my code seriously.
|
| I actually had a way more advanced, but very buggy script I
| used for "multi boxing", which is when you pay for multiple
| accounts and play them simultaneously. I used WASD, TFGH,
| IJKL, for moving 3 characters simultaneously, the numpad
| for targeting, and ctrl/shift/alt + number-row for casting
| spells on any of the windows. So ctrl+2 would cast the
| warrior 2nd ability, shift+alt+4 would cast the druid and
| mage 4th ability, ctrl+shift+alt+2 would cast all
| character's 2nd ability, etc.
|
| Blizzard used to be a lot more lax about macros[0], and
| they liked multiboxing because it was more money. I had a
| GM message me once to confirm I was playing all 3 and not
| afk botting. We chatted about AHK and how he wanted to
| learn to code.
|
| [0] also the tools to detect macros were way worse back
| then, it might have been that they just accepted it rather
| than actually embracing it.
| jabroni_salad wrote:
| Blizzard does ban for autohotkey, and even stuff like
| gaming keyboard macros.
| amelius wrote:
| I'm wondering, why introduce a new scripting language;
| wouldn't it make more sense to release it as e.g. a Python
| library? Or something that you can script with Bash?
| squeaky-clean wrote:
| Well this was back in the Python 2.4 days, I don't think I
| had even heard of it. And bash isn't easily available on
| Windows, at least interacting with running win32 programs.
| Back then it was even worse, I think I used mingw32 when I
| needed that? Blizzard did offer some sort of official macro
| system using Lua, but that was a bit advanced for me at the
| time.
|
| A dedicated language is nice because the syntax can be
| optimized for its purpose. As a teen with little coding
| experience, AHK was so easy to get simple ideas working.
| Often one easy line of code.
|
| Some of the bigger monstrosities I wrote would have
| definitely been more manageable in another language, but
| then I'd have to handle always-active input listening,
| window management, emulating the keyboard and cursor,
| reading screen pixels, my own state machine for key
| chording, and so on. Or cobble together libraries (and
| still learn those).
|
| Also probably the most important part, it was fun to work
| with and immediate. I wasn't a professional (or even good)
| programmer. But I had a goal in mind and AHK never made me
| want to quit.
| paulryanrogers wrote:
| Wayland support when ~Civvie~?
| account-5 wrote:
| Like another commenter I learned to program with AHK. I've used
| it for automating dispetate software that didn't natively talk to
| each other, automate MS Office tasks via COM objects (think VBA),
| make use of DLLs for certain tasks, and obviously for text
| expansion and replacement.
|
| I've always looked for software similar for Linux but nothing
| comes close.
|
| The documentation is second to none as well.
|
| Anyway I'm really happy to see this, well done I hope it all goes
| well.
| keybored wrote:
| The state of GUI automation and keyboard remapping on Linux is
| pretty meh. AutoHotkey seems pretty bespoke but it might be the
| best option right now.
| BiteCode_dev wrote:
| I see the benefit in this, having one script that works
| everywhere.
|
| It's also good to know linux has autokey
| (https://github.com/autokey/autokey) for the same result. The
| name is close, but it's a different project.
|
| It's not compatible with autohotkey, but you can script using
| python. I used it to enter dates, emails and automatize
| dynalist.io actions.
| app4soft wrote:
| Good addition.[0]
|
| [0] https://en.wikipedia.org/wiki/AutoKey
| infogulch wrote:
| I learned programming with AHK back in the day.
|
| One neat feature is that you can bundle a bunch of scripts with
| the runtime into a single file binary for easy distribution. If
| AutoHotkey runs on multiple operating systems, maybe combining
| this with cosmopolitan libc into an 'actually pdrtable
| executable' would let you bundle a script and use it across
| different OSes. That'd be pretty fun.
| phil294 wrote:
| Yes it's awesome and works on both platforms. But these are two
| different, independent runtimes both highly dependent on their
| target systems, so there can be no cross-os binary. For that,
| maybe ahkx [1] (abandonware) could be feasible because it
| builds on Wine, or, much rather, KeySharp (linked above).
|
| [1] https://github.com/tinku99/ahkx
| themodelplumber wrote:
| Interesting, I'm curious though, how does one interact with a
| bunch of scripts that are in a single binary?
| infogulch wrote:
| Ah I could be a bit more clear, it's more like a script and
| its dependencies. That said, you can combine a bunch of
| different utilities into a single script and select between
| them at runtime (cli, gui, etc) or even have them running in
| parallel in the same runtime without too much trouble, though
| you have to be careful since some scripts make cavalier use
| of the global namespace.
| [deleted]
| mathverse wrote:
| I like seeing languages like Crystal in the wild! Good job.
| thecrumb wrote:
| The _one_ thing I miss from Windows is AHK. Thanks for posting
| this!
| pomatic wrote:
| Perhaps this is the wrong place to ask, but it seems relevant.
| Having skimmed the documentation I can't see any options around
| automating selection/clicking of dialogue box buttons?
|
| I have a user who has limited dexterity, and the ability to have
| a macro that selects/clicks on (modal?) dialogue box buttons
| based on their label (OK/Cancel etc.) would be a life saver for
| them. (A pre-determined set of keystrokes based on knowledge of
| the tab order would not work - this needs to be generic, based on
| the button text for my application.)
|
| As things stand, I'm looking at hacking a video capture device
| and openCV together, but I can't help but think this must be a
| solved problem and I just have poor google-fu?
| llanowarelves wrote:
| Have you tried Sikuli? It uses OpenCV in the way you want.
|
| http://sikulix.com/
| stavros wrote:
| How fast is it? I tried to do something similar myself but it
| pegged a CPU core for 5 fps.
| chefandy wrote:
| Out of curiosity is there a reason you're not just biting the
| bullet and going with a more accessibility-focused proprietary
| OS? Seems like a big compromise for supporting FOSS, so I'm
| sure there's more to it. Always interested in hearing
| accessibility-involved use cases as an interface designer.
| ttnj9ZKCVQAAbxK wrote:
| You could probably do it pretty easily for _some_ dialogs, i.e.
| those drawn by some framework or other. But good luck doing it
| for all the other frameworks too. Your thought is probably the
| most effective...
| phil294 wrote:
| > I can't see any options around automating selection/clicking
| of dialogue box buttons?
|
| I can only give you some technical details for ahk_x11 here. It
| would be ControlClick I think, here [1] is the Windows docs for
| it. Not present on ahk_x11 right now, I plainly don't know if
| it is possible yet [2]. If it is, I definitely want to have it.
| Other than that, I can only think of clicking on fixed
| coordinates, such as `MouseClick, left, 200, 300`. I haven't
| done `CoordMode` yet which would be rather important for that,
| out of sheer prioritization. For a generic solution, there's
| also ImageSearch [3] for more recent Windows AHK versions which
| I'd like to have at some point too. Some OCR command would be
| cool as well.
|
| This will all take a while though, if nobody else joins in.
|
| Thanks for your viewpoints though, I agree with the sibling
| comment that these insights are valuable.
|
| [1] https://www.autohotkey.com/docs/commands/ControlClick.htm
| [2] https://github.com/phil294/AHK_X11/issues/3 [3]
| https://www.autohotkey.com/docs/commands/ImageSearch.htm
| yewenjie wrote:
| I have never used AHK before. Can someone please explain to me
| what _could_ it bring to the Linux world given that scripting is
| much easier in general?
| bcassedy wrote:
| I've used it pretty extensively in Windows to expand text,
| execute clicks on certain buttons in GUIs, execute clicks on
| specific coordinates on screen or within a window, and to
| combine all these things into complex macros.
| BeetleB wrote:
| Here are a few things I've done in AHK on Windows:
|
| 1. Move cursor to the toolbar icon of an app, right click,
| navigate menus, and select an option (all with one keystroke).
|
| 2. Click a button in one program. Copy file. Switch to Excel.
| Switch to the right worksheet. Click a VBA button. Switch to
| another sheet. All with one keystroke.
|
| 3. With one keystroke, set certain settings in Visual Studio
| (via the menu) and run the debugger.
|
| 4. With a keystroke, sign out of Teams/Skype.
|
| 5. Launch screenshot program, present me with a dialog box
| asking for filename, and have it save the screenshot in a
| directory and provide me an Org-mode link to the saved file.
|
| These are all "easy" in AHK. I never learned it well enough to
| do more advanced stuff.
| BeefWellington wrote:
| You can do similar things with xdotool (actually a lot more
| complex things) but it's missing a good GUI-based recorder
| tool.
| mkl wrote:
| xdotool does about a quarter of what AutoHotKey does, and
| even combined with sxhkd, Espanso, Autokey etc. still
| doesn't match up. xdotool doesn't do hotkeys itself, and
| doesn't work well being run with hotkeys involving
| modifiers (yes I'm aware of hacks involving getting xdotool
| to release modifier keys - I haven't succeeded getting them
| to work for anything nontrivial). AutoHotKey also does
| hotstrings (Espanso is the closest Linux equivalent I know,
| and doesn't work as well IME), app- or window-specific
| behaviour, and more.
| flarg wrote:
| It automates your desktop with a mini programming language that
| can be used to build desktop apps; but it's the text expansion
| capabilities that are highly prized, working across all desktop
| and web apps and saving you 100s of hours of typing.
| bbkane wrote:
| https://github.com/espanso/espanso does just this if it's all
| you need
| checkyoursudo wrote:
| Back when I used Windows and played MMOs during the Vista or 7
| days, I used AHK to do all sorts of grind-y tasks in-game. For
| example, grinding professions in SW:G to try to unlock Jedi
| (game might have survived if you could just pick Jedi classes
| from the start, just saying ...) and similar painful mechanics
| in most MMO(RPGs at least).
|
| I did use PyUserInput/PyMouse to "play" Universal Paperclips
| one time on Linux. Similar, though not nearly as featured, to
| AHK.
| michaelcampbell wrote:
| On Windows I use it as a text-expander. @<x><y> sans chevrons
| expands to my email address, and I have many of these.
| phil294 wrote:
| It's a simple and valid question, but I'm afraid the answer is
| rather nuanced. Most things you do with AHK are also possible
| on Linux in general, but in a much more fragmented way. AHK (in
| its complete form) unifies most functionality of xbindkeys,
| xdotool, GUI creation (no common tool I am aware of), popups,
| wmctrl, unix tools like echo/cp/, assistive technology, window
| manager tools, grabc, and many more, out of which some aren't
| even possible without sophisticated programming like Hotstrings
| (auto-replace while typing), ImageSearch, StatusBarGetWait and
| all those things. It also ships with many common programming
| language features such as math operations, and brings its own
| equivalents to unix tools like FileCopy and FileAppend.
|
| Then there's also AHK's ease of use, which also makes it
| appealing to non-programmers or beginners. Every piece of logic
| (even loops etc) is basically encapsulated in a single-word
| command instruction, almost like ASM, but for humans. You
| create GUIs with `Gui, add, button`, maximize windows with
| `WinMaximize Firefox`, hotkeys with `a::MsgBox You pressed a`
| and so on, and all of that with basically no code. I'd
| recommend you take a short look at the AHK documentation, such
| as the intro or alphabetical list of commands. It gives you an
| idea of what you can do with it.
|
| Besides, the entire language is visually oriented (and so is
| this implementation of mine): You create, edit, run, reload,
| and (optionally) compile scripts usually not by using terminal,
| but by context menus. This makes it far more accessible for
| people migrating from Windows, apart from the fact that you can
| apply your acquired AHK skills from Windows.
|
| Finally, I have found that the existing Linux automation-
| specific tools (which mostly boils down to xdotool) are, in
| comparison to Windows AHK, inferior. Getting Windows-like
| automation functionality on Linux is quite a task. The main
| difference is that very often, you just don't _need_ Window or
| Hotkey automation on Linux, because most programs are CLI-
| first, thankfully.
| llanowarelves wrote:
| Awesome comment.
|
| It shows a failure of the "Unix Way" imo. Everyone hand-
| rolling their homebrew combination of 20 different tools
| together is sometimes not the best way to go.
|
| We can look at Docker, Kubernetes, Dropbox(etc), desktop
| environments, and many other things to see that people
| greatly value almost the complete opposite approach, within
| some sweet-spot.
| geocrasher wrote:
| I wrote this almost a decade ago, and it's still relevant:
|
| https://www.tidbitsfortechs.com/2013/10/using-autohotkey-to-...
| pp19dd wrote:
| For developer work, it can automate an entire sequence of GUI
| annoyances into a hotkey. I'm making this sequence up because I
| don't recall how it exactly went, but the volume of bizareness
| was about right. AHK helped me painlessly build JAR files in
| Eclipse. I'd hit F12 and:
|
| AHK would pull up file menu, export menu, select java, type jar
| filename, hit next, select jar file, confirm overwrite, next,
| next, select seal the jar, yes overwrite, click that one random
| dialog button that's bizarrely not hotkey selectable, type main
| class as 'default.java', next, confirm, click finish. Click
| confirm again despite finish because GUI. And bam, another JAR
| file ready to test.
| tastyfreeze wrote:
| I use AHK to script interactions with a GUI application that I
| support but don't control the source or database. It allows me
| to script some repetitive tasks in the GUI and trigger them
| with a defined key sequence.
| iafiaf wrote:
| AHK is excellent; created a fishing bot during the hardcore WoW
| raiding days (Stonescale eel for Flask of Titans, anyone?)
| beering wrote:
| It looks like the calls needed to control a GUI application are
| not yet implemented. Does anyone know of a Linux tool that can do
| GUI automation? E.g. find window A, click menu B, click menu item
| C...
| verdverm wrote:
| https://github.com/hofstadter-io/self-driving-desktop
|
| cross platform self-driving mouse & keyboard, can also record
| deadbunny wrote:
| xdotool?
|
| https://github.com/jordansissel/xdotool
| mappu wrote:
| Sikuli works on Linux - http://sikulix.com/
| geocrasher wrote:
| AHK is GOLD for me. Power user? Sure. But it ties me to Windows
| only, and so I'm VERY keen to see a version for another OS.
| AutoKey failed miserably in my testing, and I have so much tied
| directly to AHK that I'm okay with choosing Windows to run it.
| There's a lot of other things that are Windows-only for me, so
| it's not a big deal. I actually LIKE W10 and W11. But it's great
| to have options!
| RMPR wrote:
| Shameless plug https://atbswp.com not as powerful, but good
| enough for quick hacks.
| xtracto wrote:
| This is so great! I have fond memories of AutoHotkey when I used
| Windows. It has just the right balance between scripting
| requirements and features.
| chrismorgan wrote:
| Isn't it a bit late to do something like this tied to X? I get
| the impression almost all distributions now default to Wayland.
| This feels like something that would have been good a decade ago,
| but is too late now.
|
| (Mind you, this would be a good deal harder to implement in
| Wayland, where possible at all, since Wayland is predicated
| around a security model where this kind of thing is deliberately
| not supported. You can either go with something compositor-
| specific, and I don't know if this is possible for all
| compositors, though I get the _impression_ that it should be
| possible for at least wlroots; or work more the way ydotool does,
| where possible, in basically providing a fake input device.)
| [deleted]
| viraptor wrote:
| Related proposal:
| https://gitlab.freedesktop.org/wayland/wayland-protocols/-/m...
| yjftsjthsd-h wrote:
| I mean, as you note, Wayland almost certainly can't provide
| this kind of functionality by design. It offers some ways to
| fake input, but AFAIK no way to hook/listen to input events
| without hoping that each compositor adds a way to do so. In
| contrast, X11 trivially enables read and write access to input
| events, as well as the ability to intercept input and rewrite
| it before applications see it. Also, while many distros now
| ship Wayland as the nominal default, last I'd seen it was
| actually _used_ by a minority of users compared to Xorg (if we
| exclude ChromeOS, which seems reasonable for this
| conversation).
| smartmic wrote:
| > Also, while many distros now ship Wayland as the nominal
| default, last I'd seen it was actually used by a minority of
| users compared to Xorg
|
| You touched a good point. The one and only metric to measure
| success in software is the number of active users. However, i
| do not know of any statistics Xorg vs. Wayland users.
| Personally, i have no reason to switch away from X11. In
| contrary, it was and is a loyal companion now already for
| decades. I trust the Lindy effect that X11 will stay relevant
| for a very long time. So kudos for the OP for creating this!
| phil294 wrote:
| Wayland will be an interesting challenge, but I think there's
| still plenty of time before that happens.
|
| If we figure out that this kind of automation is impossible on
| Wayland, I think it should still be possible to hook into the
| raw keyboard events with kbd and such, no? Requires root
| though.
| halz wrote:
| There is some rough functionality for operations with wlroots
| via wlrctl https://git.sr.ht/~brocellous/wlrctl and more
| generically (via uinput) ydotool
| https://github.com/ReimuNotMoe/ydotool
| guilhas wrote:
| Good work
|
| I have used AHK a lot and looked for a Linux alternative in the
| past, like AutoKey, Actiona... which did not felt as good
|
| But nowadays I think I prefer the "Linux way" tools, the bulk can
| be done with: sxhkd, bash, zenity, xdotool, expanso...
|
| AHK is all-in-one personal automation tool, very useful in
| Windows, a single tool with a unified language
|
| Linux has a CLI tool for everything, more disperse, different
| implementations, but easier to re-use modules elsewhere
|
| Still choice is good
| chillpenguin wrote:
| Anyone know of a comparable program for macOS?
| akerr wrote:
| Keyboard Maestro? The built-in AppleScript, Services and
| Keyboard shortcuts support?
| woodruffw wrote:
| Nice work! And thanks for the x_do.cr shoutout :-)
| stavros wrote:
| I've been looking for something that can recognize the mute
| button in call software (Zoom, Meet, etc) and click it, but
| everything I've found seems to do image detection.
|
| I understand that running in a browser makes things hard, but is
| there a better method? I guess I could write an extension for
| Meet and Jitsi, but Zoom would then be the odd one out.
| voat wrote:
| Nut.js
| [deleted]
| marcodiego wrote:
| Does it work with Wayland?
| zcam wrote:
| No
| themodelplumber wrote:
| You did this? Nice job!
|
| > Please also check out Keysharp, a WIP fork of IronAHK, another
| complete rewrite of AutoHotkey in C# that tries to be compatible
| with multiple OSes and support modern, v2-like AHK syntax with
| much more features than this one. In comparison, AHK_X11 is a lot
| less ambitious and more compact, and Linux only.
|
| Fascinating, lots to check out here. Thank you.
|
| BTW this kind of work falls into poweruser tools IMO, which is an
| important area for cultivation of Linux Desktop focus.
| Traditionally in the Linux community this has been more of a
| distro-maintainer's support choice (offer poweruser tweaks and
| tools, or not) so it's always nice to see new distro-independent,
| non-dev-poweruser options coming into being.
| Vanderson wrote:
| Thank you! I haven't tried it yet, but this was one of the only
| things that I sorely missed when I went from Windows to Linux.
| nooyurrsdey wrote:
| Love the project but I really wish projects (especially linux
| projects) would include a "plain english" description of what
| this does at the top. Like, even one sentence.
|
| 1. Not everyone knows what AutoHotkey is and what it does. I had
| to google it.
|
| 2. Not everyone speaks english. Diving into a description that
| includes words like "fault tolerant, extensible, high
| availability" so infuriatingly confusing.
| frostwarrior wrote:
| I don't think that (2) is OP's fault.
|
| Look the words up in a dictionary. It's ok not to know and to
| learn but you shouldn't expect everyone to adapt to your lack
| of knowledge.
| InCityDreams wrote:
| ....explain it like I'm 5 years old?
| capableweb wrote:
| If everyone wrote software to be used by 5 years old
| without any interest in looking up things they don't
| understand (yet) themselves, we'd never move the field
| forward.
| xupybd wrote:
| AutoHotKey is not normally aimed at developers but highly
| skilled administrators. If you target your advertising at
| this market you would likely get more traction.
|
| Moving the field of software development is about solving
| more problems for people without putting a large learning
| curve in their way.
|
| Yes some aspects will always require expertise but that
| is not an advantage.
| Vrondi wrote:
| Dictionary is good for learning words.
| ttnj9ZKCVQAAbxK wrote:
| A dictionary probably won't give you a useful definition for
| most of those terms. They're jargon.
|
| But then again I would add (3) they're just buzzwords that
| don't actually tell you anything...
| OJFord wrote:
| Perhaps not HA, but 'fault tolerant' and 'extensible' are
| pretty apt.
| phil294 wrote:
| 1. Thank you for the suggestion. I added the one-liner
| description from the Windows website to the top of the Readme.
|
| 2. Those words aren't in the Readme so I'm a bit confused. I
| guess these were just examples though. I am not a native
| speaker either though... if you really think there's uncommon
| words to be found, I would welcome a PR.
| dotancohen wrote:
| > I added the one-liner description from the Windows website.
|
| Bad idea, you don't need an infringement case. Try this
| instead: "An easy to learn language for automating your Linux
| computer". People who don't know what AHK is don't care that
| this project is a port of it, so no need to mention that in
| the description.
| krsdcbl wrote:
| tbh your suggestion would confuse me as well, i think the
| scope or better said usp of ahk is more specific, and the
| proposed description could very well mean bash or other
| comparable tools
| boredtofears wrote:
| #2 is pretty common software lingo. If you're esl you
| definitely are going to want to look that one up.
| boomskats wrote:
| Does anyone know of a stable way to implement SpaceFN under X?
|
| Apologies for the hijack, but this thread feels like the right
| place to ask.
| lvass wrote:
| xcape.
___________________________________________________________________
(page generated 2022-08-30 23:00 UTC)