68

Is there an equivalent product/method for AutoHotkey?

For those that don't know, it's a product that allows you to program your mouse movements and keyboard. This allows me to "macro" certain functions on programs instead of having to do it manually. In the old days they used to call them keyboard stuffers. But that is only half of the solution as I need a "mouse movement" stuffer as well.

Is there such a beast?

7 Answers 7

38

There's a port of AutoHotKey to Linux called IronAHK and a similar tool called Autokey. I haven't used either, I don't know how well they work.

Other than such programs, you won't find exactly the same kind of automation tools. The basic user automation tool on unix systems is the shell. The shell is the glue that combines other tools: it can launch external programs and control how they exchange data. The shell itself doesn't include anything to manipulate GUI concepts like windows and the mouse pointer¹. What you do is call specialized tools in a shell script, in particular xdotool to manipulate windows, and inject keystrokes and mouse events.

For example, the following script clicks at the position (40,20) in the window of Myapp.

#!/bin/sh
xdotool search --class Myapp \
        mousemove --window %1 40 20 \
        click 1

¹ Except for dtksh, but I've never seen a Linux port of it.

3
  • Nice summary, pity the project is 4 years out of date and the binaries are all 404's, will give the xdotool a try though. Thanks for taking the time.
    – Meer Borg
    Oct 31, 2014 at 6:36
  • 1
    tried out xdotool, works like a charm but you should definitely read their docs before starting Sep 16, 2016 at 13:59
  • 2
    AFAIK, IronAHK never got fully implemented and has been abandoned.
    – Joe
    Aug 1, 2019 at 16:07
9

There are several projects that address this. The two most active ones, AFAIK, are sikuli and AutoKey (a project I help support.)

I have not used sikuli, but it appears to be based on finding patterns on the screen and triggering actions based on them.

AutoKey allows the user to define trigger phrases and hotkeys which expand phrases (similar to a very powerful autocorrect feature) or run scripts written in Python3 that are only limited by the user's programming skills. It provides an API for keyboard and mouse event generation. It also integrates with Xautomation which allows you to find a small image on the screen and move the mouse cursor to it.

I have been using AutoKey for many years and supporting it on our list. It's like a number of productivity tools: you can get by without it, but once you start using it, you'll wonder how you ever did without it.

Some specifics:

AutoKey does not work with AutoHotKey definitions and scripts. They will have to be rewritten.

I did write a proof of concept bash script (available upon request) which translates AutoHotKey phrases into AutoKey phrases, but it is only a starting point and ignores most of AutoHotKey's options.

Since AutoKey scripts are written in Python3, it is also possible to call out to tools such as xdotool and wmctrl from within a script to provide additional functionality, but this is typically not necessary. Although AutoKey scripts are written in Python, quite a lot can be accomplished with a very limited knowledge of Python. You don't need to be a fluent Python programmer for most purposes.

If you use a Debian-based distribution, please don't install the version of AutoKey provided by your distribution. Their AutoKey package is unmaintained and very old. Get a current version from us. Edit: This was corrected in Debian testing and derivatives in 2020. They now offer the most current release.

0
4

Here's a noob solution for noobs like me:

Most Desktop Environments (DE) include a built-in keyboard shortcut editor. Using the shortcut editor, you can write custom bash scripts, console commands, etc.

To get AHK-like functionality beyond what your DE makes possible via custom shortcuts, install xdotool (sudo apt install xdotool) and write your xdotool commands into the shortcut editor (if you're given options for several types of shortcuts, select the "command" option):

xdotool [command]

(Enter man xdotool in the terminal to access the xdotool manual.)

If you use xdotool to extend your custom shortcuts, it's a good idea to enter your command in the terminal before setting it as a hotkey, just to make sure it works as expected.

I have yet to figure out how to get AHK-like hotstrings in Linux, but I'll update if I discover a workable solution.

3

You can use xautomation in Linux. I use it on Raspberry Pi display screens, to send F5 page refreshes and 'Return' (enter) keystrokes for logins.

3

Use AutohotkeyX, it's a recent WINE port of autohotkey which, according to winehq testing, does everything that Autohokey is able to do on windows. It's easily the best and most straightforward answer.

https://appdb.winehq.org/objectManager.php?sClass=version&iId=17738

I haven't personally tested this, but WINEHQ results tend

0

Download Autohotkey on Linux. Create a Autohotkey file (example.ahk). Use wine to run Ahk2Exe.exe from the Autohotkey folder. Compile your example.ahk file to example.exe Use wine to run example.exe

1
  • 2
    It's not a good option. For now, the functionality of Autohotkey run through wine is very limited: appdb.winehq.org/….
    – banan3'14
    Sep 7, 2018 at 18:06
-4

Just use XEV and XMODMAP. SIMPLE and better than dedicated programs or emulating crappy Windows apps. All my LINUX stuff uses scripts to redefine keys and change screen modes and then, when the program is done and exits, set everything back to normal. It's about just as easy to use XMODMAP and make a script as it is to make an AHK script, but with the added bonus of not having to run an emulated Windows app.

1
  • 8
    This answer might, for all I know, be 100% correct and accurate.  However, it would be a lot more useful if it included some examples and / or instructions, or even links to further documentation.
    – Scott
    Jul 10, 2019 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.