In my daily life I'm always typing <kbd>Keyboard Character</kbd>
and I'd like to set up a macro in Ubuntu to automatically enter <kbd> </kbd>
.
I'd like to assign it to say Shift+Control+K or whatever keyboard control character combination isn't assigned and already used by Ubuntu.
Back in the day of TSR (Terminate and Stay Resident) MS-DOS programs this was possible. Certainly it must be in Ubuntu too?
Do I have to write a daemon to accomplish this?
I found other questions with no answers: How can I assign macros to my keyboard keys on Ubuntu, similar to Razer Keyboard Macros in Windows?, what is a good mouse/keyboard macro recorder?
I found a similar question with an answer: Can I use Keyboard Shortcuts to implement text macros?. However that question stipulated the answer could not be AutoKey
.
I did some googling and found a program called AutoKey (Autokey - Linux utility for text substitution hotkeys) near the top of the list.
Rather than a hotkey using Ctrl+Shift+K I chose to assign the abbreviation
kz
which is automatically expanded into<kbd></kbd>+
.It is simply installed using:
It installs in Launcher and the screen is pretty simple to use:
What also can be done is to use
xdotool
withtype
flag, like so:Go to System Settings-> Keyboard-> Shortcuts -> Custom and bind that command to whatever keyboard shortcut you want. I chose CtrlSuperK. What happens here is that we give user delay of 0.5 seconds to release keyboard shortcut, and then
xdotool
will type out the key markup tags just as if you were doing it yourself on keyboard. Very easy and simple approach. In fact I am used it just now to put in those 3 keys above.Note that
xdotool
doesn't come with Ubuntu by default, so you will have to install it viasudo apt-get install xdotool
If you have a compose file you can use it as a poor-man’s text insertion utility.
You can use a few of the modifiers in X. Apparently you can use
Shift
as a modifier:But this does not work, at least on my machine.
Nor does this work (omitted
Shift
, capitalizedK
):However, you can use
Ctrl
andCtrl
+Alt
:Placing the cursor correctly
The above mappings will place the cursor after the string (
|
indicates the cursor):I reckon there can be no general-purpose solution for putting the cursor inside of the tag; for that you would need to use a fit-for-purpose tool. But you can the cursor go inside the tag in certain applications.
I use
gnome-terminal
with Bash which uses readline keybindings (Emacs-like).Ctrl-b
is the keybinding for going backwards one character. In my terminal I can typeCtrl+v b
and get the control character^B
(U+0002 (Start of Text)). So type six of these characters at the end of the string:The cursor will be placed inside the tag if you are inside an application that interprets
^B
correctly (e.g. terminals and Emacs):Using the compose key
You can of course use the compose key (
<Multi_key>
) to achieve the same thing. For example, uset
(“tag”) andk
(“keyboard”):