In short, I want to map Ctrl+H/L to Ctrl+Left/Right without autokey
, and xbindkeys
+xdotool
/xvkbd
does not work. Details are as follows:
I am now using autokey
to achieve the mapping, it works very good, but in some application it fails to work because autokey
is a high-level application. So I want to achieve a low-level key map.
Application such as xmodmap
and xkb
cannot do this because Ctrl+Left/Right is not a keysym. I have tried xbindkeys
+xdotool
. The following configuration script for xbindkeys
does not work:(to simplify the question, I map the keys to 'a' instead Ctrl+Left/Right)
#.xbindkeys
"xdotool key a"
Control+h
I think it is because the pressed keys influence the execution of xdotool
, because the following works:
#.xbindkeys
"xdotool key --clearmodifier a"
Control+h+Release
But I just do not want to trigger the command when I release the key, I want it to take into effect immediately when I press the key, so I change the configuration to:
#.xbindkeys
"xdotool keyup h; xdotool key --clearmodifier a"
Control+h
This configuration still works, but it cannot achieve autorepeat, that is when I press the key board without release for a long time, the command only execute one time. I have also tried xvkbd
but is does now work:
#.xbindkeys
"xvkbd -text 'a'"
Control+h
Can anyone give me some help to achieve my key map?
Sorry, I underestimated the power of xkb, it can do much more than I thought. It is the most basic and overall keyboard manager of X-server. I have met my requirement using xkb. A very useful tutorial can be found at here on the Arch Linux Wiki, if you are also interested in how to do that. It is also welcomed to post on this topic.
Here are the details for my case (though I strongly recommend reading the linked page because it is very useful and not too long):
First, get your present keyboard layout:
Then open the
.config.xkb
file with some editor, say vscode. You can see the file consists of 5 blocks(keycodes, types, compatibility, symbols, geometry):In the
xkb_types
block, add:In the
xkb_symbols
block, find the following two sub-blocks:And change these two sub-blocks to:
Finally, reset the keyboard layout to the modified one:
Appendix
In case that one will want to know how to map to Left/Right instead of Control+Left/Right, I add the appendix.
The only change is to replace the sub-blocks in
xkb_symbols
block with