Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use AutoHotkey in Linux

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use AutoHotkey in Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

AutoHotkey is a simple and powerful hotkey scripting language. Users can record the movements and clicks of keyboards, mice and even game joysticks.

Install and set up AutoKey

AutoKey is an off-the-shelf package in many Linux distributions. The installation guide for the project contains instructions for many platforms, as well as instructions for building from source code. This paper uses Fedora as the operating platform.

There are two variants of AutoKey: autokey-gtk designed for GTK-based environments like GNOME, and autokey-qt based on QT.

You can install any variant from the command line:

Sudo dnf install autokey-gtk

After the installation is complete, run it using autokey-gtk (or autokey-qt).

Explore the interface

Before setting AutoKey to run in the background and perform operations automatically, you first need to configure it. Call up the user interface (UI) configuration:

Autokey-gtk-c

AutoKey provides some examples of preset configurations. You may want to keep them as a backup when you are familiar with UI, but you can delete them as needed.

The left pane contains a folder-style phrase and a hierarchy of scripts. Phrases represent the text you want AutoKey to enter. Scripts are dynamic, programmatic equivalents that can be written in Python and get basically the same results as keyboard keystrokes sent to the active window.

The right pane builds and configures phrases and scripts.

Once you are satisfied with the configuration, you may want to run AutoKey automatically when you log in so that you don't have to start it every time. You can configure it by checking "start automatically on login" in the preferences menu (Edit-> preferences).

Using Linux Automation tool AutoKey to improve Productivity using Linux Automation tool AutoKey to improve Productivity using AutoKey to correct Common typesetting errors

Fixing common typesetting errors is an easy problem for AutoKey to solve. For example, I always type "gerp" instead of "grep". Here is how to configure AutoKey to solve these types of problems for you.

Create a new subfolder where you can group all typesetting error correction configurations. Select My Phrases in the left pane, and then select File-> New-> subfolder. Name the subfolder "Typos".

Create a new phrase in File-> New-> phrase. And call it "grep".

Configure AutoKey to insert the correct keyword by highlighting the phrase "grep" and then typing "grep" in the input phrase content section (replacing the default "Enter phrase contents" text).

Next, set how AutoKey triggers this phrase by defining an abbreviation. Click the set Set button next to the acronym at the bottom of the user interface.

In the pop-up dialog box, click the add button, and then add "gerp" as the new abbreviation. Check "remove typed abbreviations"; this option causes AutoKey to replace any typing with the word "gerp" with "grep". Do not check "trigger when typing part of a word" so that if you type a word that contains "grep" (such as "fingerprint"), you will not try to convert it to "fingreprint". This feature is valid only if you type "grep" as a separate word.

Restrict corrections to specific applications

You may want to apply corrections only when typesetting errors occur in some applications, such as terminal windows. You can configure it by setting the window filter. Click the set Set button to define it.

The easiest way to set a window filter is to have AutoKey detect the window type for you:

Start a new terminal window. Return to AutoKey and click the detect window Properties button. Click the terminal window. This automatically populates the window filter, and the possible window class value is gnome-terminal-server.Gnome-terminal. This is enough, so click "OK".

Save and test

When you are satisfied with the new configuration, be sure to save it. Click File, and then select Save for the changes to take effect.

Now take the important test! In your terminal window, type "gerp" followed by a space, and it will automatically correct to "grep". To verify that the window filter is running, try typing the word "gerp" in the browser URL bar or another application. It hasn't changed.

You might think that using shell aliases can easily solve this problem, and I totally agree! Unlike aliases, AutoKey can correct errors according to the rules as long as it is command-line oriented, no matter what application you use.

For example, another common typing error I typed in browsers, integrated development environments, and terminals: "openshfit" was replaced by "openshift". Aliases do not completely solve this problem, and AutoKey can correct it in any case.

Type a common phrase

There are many other ways you can call AutoKey phrases to help you. For example, as a site reliability engineer (SRE) working on OpenShift, I often enter the Kubernetes namespace name on the command line:

Oc get pods-n openshift-managed-upgrade-operator

These namespaces are static, so they are ideal phrases that AutoKey can insert for me when typing specific commands.

To do this, I created a short phrase subfolder called "Namespaces" and added a phrase entry for each namespace I frequently typed.

Assign hotkey

Next, and most crucially, I assigned a "hotkey" to the subfolder. Every time I press the hotkey, it opens a menu where I can select the phrase I want to insert (either use the "arrow key" + enter key or use a number). This reduces the number of keystrokes that I can enter these commands with just a few keystrokes.

The preconfigured example of AutoKey in the My Phrases folder is configured using Ctrl+F7 hotkeys. If you keep the example in the default configuration of AutoKey, please give it a try. You should see a menu of all available phrases here. Use the numbers or arrow keys to select the desired item.

Advanced automatic typing

AutoKey's scripting engine allows users to run Python scripts that can be called by the same acronym and hotkey system. These scripts can perform operations such as switching windows, sending keystrokes, or performing mouse clicks through supported API functions.

This feature is welcomed by AutoKey users and custom scripts have been released for other users to adopt. For example, when a NumpadIME script converts a numeric keypad to an old mobile phone-style text input method, Emojis-AutoKey can do this by changing things such as:? Such phrases are converted into their equivalent emoticons for easy insertion.

This is a small script I set up that enters Tmux copy mode to copy the first word from the previous line into the paste buffer:

From time import sleep# sends the Tmux command prefix (b changed to s) keyboard.send_keys ("+ s") # Enter copy modekeyboard.send_key ("[") sleep # Move cursor up one linekeyboard.send_keys ("k") sleep # Move cursor to start of linekeyboard.send_keys ("0") sleep # Start markkeyboard.send_keys (") sleep # Move cursor to end of wordkeyboard.send_ Keys ("e") sleep (0.01) # Add to copy bufferkeyboard.send_keys ("+ m")

There are sleep functions because Tmux sometimes fails to keep up with the speed at which AutoKey sends keystrokes, and their impact on the overall execution time is negligible.

The above is all the content of the article "how to use AutoHotkey in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report