I want to realize something like AutoHotkey with AutoKey on Ubuntu (Kali Linux)

Introduction

My main machine is Windows. I don't want my hand to move away from the home position when I press the cursor keys or function keys, so I use AutoHotkey to set it so that I don't have to leave the home position as much as possible.

Related article: -I want to withdraw to the home position of the Japanese keyboard with AutoHotKey -Google search anytime, anywhere with Autohotkey

Recently, I have more opportunities to use Kali Linux, but since Linux does not have AutoHotkey, keyboard operation was troublesome. However, by using software called AutoKey, we were able to achieve something similar to AutoHotkey, such as being able to move the cursor without taking your hands off the home position and being able to perform a Google search with zero mouse operation.

I know there is no demand, but I'm a person who loves keyboard metamorphosis settings, so I'll write it here. The version of Kali Linux is 2020.2.

Requirement definition

--I want to move the cursor up / down / left / right by pressing "Convert" and the h, j, k, l keys (any of them) at the same time (← achieved) --I want to delete one line, BackSpace, Delete by pressing "Convert" and the b, n, m keys (any one) at the same time (← achieved) --I want to convert full-width kana, full-width kana, half-width kana, and half-width alphanumeric characters by pressing "no conversion" and h, j, k, l (any of) at the same time (F7 to F10 conversion when inputting Japanese). Same as) (← achieved) --I want to move Chrome tabs with Alt + 1,2 (either) (← achieved) ――I want to switch between Japanese input and direct input just by "no conversion" (← not achieved)

policy

AutoKey creates shortcut keys with 6 types of modifier keys, Ctrl, Alt, Shift, Super, Hyper, and Meta, and other key combinations. Super is a Windows key. It seems to be called Super in the Linux world. Hyper, Meta are modifier keys found in old special keyboards and are not found in today's popular keyboards. Also, since Autokey does not support Japanese keyboards, it does not support special keys such as "convert" and "no conversion". If Hyper and Meta are not used, and "Conversion" and "No conversion" cannot be used, you should be able to do what you want by assigning "Conversion" to Hyper and "No conversion" to Meta. ..

xkb settings

Use xkb (X Keyboard Extension) to change this key binding. First, check the current behavior of xkb (the target to read the configuration file) with "set xkbmap -print".

$ sudo setxkbmap -print -verbose 10

It seems that 3 files "pc", "jp" and "inet" in the "/ usr / share / X11 / xkb / symbols" folder are being read. image.png

I'm reading three files, but this time I'm only editing "inet". Edit after backup.

$ sudo cp /usr/share/X11/xkb/symbols/inet /usr/share/X11/xkb/symbols/inet_bak
$ sudo vi /usr/share/X11/xkb/symbols/inet

There are two places to edit, and . image.png

Modify "Henkan" in \ to "Hyper_L" and "Muhenkan" in \ to "Meta_L". image.png

When you're done saving and exiting, clear the xkb cache.

$ sudo rm -rf /var/lib/xkb/*

Then restart Kali Linux.

Autokey settings

It's finally AutoKey's work. If nothing else, let's install it first.

$ sudo apt install autokey-gtk

screen structure

  1. List of saved settings
  2. Processing content (Python code)
  3. Execution condition setting
  4. Hotkey image.png

Setting method

Cut the folder from "New" in the upper left (you can do it later). I created three subfolders under the folder "MySettings": "browser", "cursor" and "input_conversion". image.png

This time, we will create a setting to move the cursor to the left when "Convert" and "h" are pressed at the same time. Select Script from New and enter a name.

Press the "Set" button in the "Hotkey" line. image.png

Press the "Press to Set" button, press the "h" key, and press the "Hyper" button. image.png

It has been set. image.png

Enter the following in the script input field at the top right of the screen. image.png

Click the "Save" button to save your input. image.png

Now, pressing "Convert" and "h" at the same time will move the cursor to the left. Follow the same procedure to create up / down / left / right, Delete, BackSpace, etc. Set the hotkey as you like. Please refer to here for the names of special keys such as cursor keys and control keys. autokey - SpecialKeys.wiki

Disable OS shortcuts

If h, j, k, l are set to move up / down / left / right, "Hyper" + "l" will be batting with "log off" set in the OS, so delete this. Select the Settings> Keyboard> Application Shortcut Keys tab.

Delete this line. image.png

Setup is completed.

Setting list

cursor

Move cursor left Hyper+h left.py


keyboard.send_keys("<left>")

Move cursor to the right Hyper+l right.py


keyboard.send_keys("<right>")

Move on cursor Hyper+k up.py


keyboard.send_keys("<up>")

Move down the cursor Hyper+j down.py


keyboard.send_keys("<down>")

delete.py Hyper+n


keyboard.send_keys("<delete>")

backspace.py Hyper+m


keyboard.send_keys("<backspace>")

Delete one line Hyper+b line_delete.py


keyboard.send_keys("<home>")
keyboard.send_keys("<shift>+<end>")
keyboard.send_keys("<delete>")

Conversion (pressed when inputting in Japanese mode)

Hiragana Meta+h hiragana_zen.py


keyboard.send_keys("<f6>")

Katakana full-width Meta+j katakana_zen.py


keyboard.send_keys("<f7>")

Katakana half-width Meta+k katakana_han.py


keyboard.send_keys("<f8>")

Alphabet Meta+l alphabet.py


keyboard.send_keys("<f10>")

Chrome tab operation

Left tab move ctrl+1 chrome_lefttab.py


keyboard.send_keys("<ctrl>+<page_up>")

Move right tab ctrl+2 chrome_righttab.py


keyboard.send_keys("<ctrl>+<page_down>")

Google search meta+g chrome_search.py (Focus on the address bar. Chrome must be running)


window.activate("Chrome")
keyboard.send_keys("<ctrl>+l")

Digression

Actually, I wanted to switch between Japanese input and direct input only with "No conversion", but I couldn't because I set "No conversion" to Meta. I think I'll substitute ctrl + space.

-** Part 2 ** By assigning Meta to "no conversion", you can now grab the window with "no conversion". It may be convenient for soberness. image.png

-** Part 3 ** The processing code seems to be Python, so I think anyone who can write Python can do more advanced things.

Reference site

-[Ubuntu: How to convert non-conversion / conversion key to Meta / Hyper key and make it a modifier key that can be customized with AutoKey](https://did2memo.net/2015/07/19/ubuntu-xkb-muhenkan-henkan- meta-hyper /) Thank you very much for your help. Thank you very much.

Recommended Posts

I want to realize something like AutoHotkey with AutoKey on Ubuntu (Kali Linux)
I want to use OpenJDK 11 on Ubuntu Linux 18.04 LTS / 18.10
I want to use shortcut translation like DeepL app on Linux
I want to use Linux on mac
I want to log file I / O on Linux
I want to AWS Lambda with Python on Mac!
I want to do something like sort uniq in Python
I want to debug with Python
I want to detect objects with OpenCV
I want to tweet on Twitter with Python, but I'm addicted to it
I want to know how LINUX works!
I want to blog with Jupyter Notebook
I want to pip install with PythonAnywhere
I want to analyze logs with Python
I want to play with aws with python
How to install php7.4 on Linux (Ubuntu)
On Ubuntu Linux, set Tab to q
I want to create an Ubuntu chrome User Profile with Colab only
I want to develop Android apps on Android
I want to improve efficiency with Python even in an experimental system (3) I want to do something like Excel with Pandas
#I tried something like Vlookup with Python # 2
I want to use PyTorch to generate something like the lyrics of Japari Park
I want to be notified when the command operation is completed on linux!
I can't install Dask with pip on Ubuntu
I want to use MATLAB feval with python
I want to analyze songs with Spotify API 2
I want to mock datetime.datetime.now () even with pytest!
I want to display multiple images with matplotlib.
I want to knock 100 data sciences with Colaboratory
I want to make a game with Python
I want to analyze songs with Spotify API 1
I want to use Temporary Directory with Python2
I don't want to use -inf with np.log
#Unresolved I want to compile gobject-introspection with Python3
I want to use ip vrf with SONiC
I want to solve APG4b with Python (Chapter 2)
I want to do pyenv + pipenv on Windows
I want to start over with Django's Migrate
I tried to operate Linux with Discord Bot
I want to write to a file with Python
[Python] I want to add a static directory with Flask [I want to use something other than static]
I tried to make something like a chatbot with the Seq2Seq model of TensorFlow
I want to get started with the Linux kernel, what is the list head structure?
I want to plot the location information of GTFS Realtime on Jupyter! (With balloon)
I want to use Mac / emacs key bindings (keyboard shortcuts) on Ubuntu xkeysnail recommendations
I want to detect unauthorized login to facebook with Jubatus (1)
Run Kali Linux on Windows with GUI (without VirtualBox)
I want to transition with a button in flask
I want to handle optimization with python and cplex
I tried to implement Minesweeper on terminal with python
I want to climb a mountain with reinforcement learning
I want to develop an Android application on Android (debugging)
less command I want to definitely remember this [linux command]
I want to find a popular package on PyPi
I made a Python3 environment on Ubuntu with direnv.
I want to inherit to the back with python dataclass
I want to split a character string with hiragana
I want to manually create a legend with matplotlib
[TensorFlow] I want to process windows with Ragged Tensor
I want to restart CentOS 8 on time every day.
What I did to get started with Linux commands