
Previously, I quite often had a situation where you simultaneously work in a terminal and, for example, in a browser.
After several hours of work, you start to get confused and in the terminal instead of [Ctrl] + [Shift] + [C], press [Ctrl] + [C], and vice versa in the browser. As a result, in the terminal you get an interrupt and in the browser, instead of the expected effect, your debugger is slowly loaded.
One fine moment it got me and I decided it was time to change something ...
Before I reinstalled OSX on Linux on my working machine, I had time to get used to the rather pleasant implementation of keyboard shortcuts. More specifically, all the basic operations, such as
Cut ,
Copy , and
Paste , all use the [Cmd] button (similar to the [Win] button on the PC), rather than [Ctrl], as it is done default on linux and windows. This is very convenient, because, I repeat, if you often work in a terminal, you have the same shortcut keys for copying and pasting as in all other applications, and the interruption always remains in its place [Ctrl] + [C].
You will also benefit from this method if you use a tile window manager, since In most cases, to use standard operations and switching between tags / windows, you do not have to remove your finger from your modkey
Of course, you can customize keyboard shortcuts in the configs of each specific application, but this is not very convenient, and not every application supports this setting. For this, I decided to just zabindit standard keyboard shortcuts for the ones that I need.
Those. pressing [Win] + [C], your terminal will think that you press [Ctrl] + [Shift] + [C], and all other applications that [Ctrl] + [C].
')
To implement our plans, we need a program that will track our clicks, for example
xbindkeys, or you can use the regular features of your window manager, and an emulator of keystrokes, there are several of them:
xdotool ,
xte and
xvkbd .
However, with the first two I had one most interesting glitch: if for example you press [Win] + [A], the emulator will pass the [Ctrl] + [A] to the application, and the application will see that all three keys [Win] + [Ctrl are pressed ] + [A] and will not process this combination. This very unpleasant bug was not easy to detect, since even the --clearmodifiers option for xdotool did not help, which, it would seem, was created especially for such a case. In xkdbb, no such behavior was noticed.Let's start with xbindkeys. Disable all CapsLock, NumLock and other modifiers, run:
$ xbindkeys -k
The window opens, in the window we press the combination [Win] + [A], in the terminal we get the following conclusion:
"(Scheme function)" m:0x40 + c:38 Mod4 + a
where Mod4 is our [Win] key. The same can be used to write the xbindkeys config:
Open
~ / .xbindkeysrc and write:
"xvkbd -xsendevent -text '\[Control_L]a'" Mod4 + a
Option for xdotool and xtexdotool
"xdotool key --delay 0 --clearmodifiers ctrl+a" Mod4 + a
xte
"xte 'keydown Control_L' 'key A' 'keyup Control_L'" Mod4 + a
Now run xbindkeys:
$ xbindkeys
And we will try to press [Win] + [A], the effect will be the same as if you pressed [Ctrl] + [A]
After you make sure that everything works, you can continue to edit the cofig, but before the next start you need to start the previous xbindkeys process from the beginning:
$ pkill xbindkeys
Ok, we figured it out, but how do we transfer different keyboard shortcuts when pressing the same buttons, depending on the program we are working with?
The same
xdotool and
xprop comes to the rescue , with the help of which we determine whether the active window is a terminal.
Let's write a simple script and put it in
/bin/copypaste.sh :
Use
xprop if you don’t know which class your program uses:
xprop
and click on the window
Do not forget to make the script executable:
# chmod +x /bin/copypaste.sh
It works like this:
$ copypaste.sh copy $ copypaste.sh paste
This is what we add to our config
~ / .xbindkeysrc :
"xvkbd -xsendevent -text '\[Control_L]a'" Mod4 + a "copypaste.sh copy" Mod4 + c "copypaste.sh paste" Mod4 + v
Similarly, customize the combinations for the rest of the keys.
Ready config:
for xbindkeys~ / .xbindkeysrc "copypaste.sh copy" Mod4 + c "copypaste.sh paste" Mod4 + v "/usr/bin/xvkbd -xsendevent -text '\[Control_L]x'" Mod4 + x "/usr/bin/xvkbd -xsendevent -text '\[Control_L]z'" Mod4 + z "xvkbd -xsendevent -text '\\[Control_L]\\[Shift_L]\\[Z]'" Shift+Mod4 + z "/usr/bin/xvkbd -xsendevent -text '\[Control_L]q'" Mod4 + q "/usr/bin/xvkbd -xsendevent -text '\[Control_L]y'" Mod4 + y "/usr/bin/xvkbd -xsendevent -text '\[Control_L]a'" Mod4 + a "/usr/bin/xvkbd -xsendevent -text '\[Control_L]s'" Mod4 + s "/usr/bin/xvkbd -xsendevent -text '\[Control_L]o'" Mod4 + o "/usr/bin/xvkbd -xsendevent -text '\[Control_L]f'" Mod4 + f
for awesome 3.5 awful.key({ modkey, }, "c", function () awful.util.spawn("copypaste.sh copy") end), awful.key({ modkey, }, "v", function () awful.util.spawn("copypaste.sh paste") end), awful.key({ modkey, }, "x", function () awful.util.spawn("xvkbd -xsendevent -text '\\[Control_L]x") end), awful.key({ modkey, }, "z", function () awful.util.spawn("xvkbd -xsendevent -text '\\[Control_L]z'") end), awful.key({ modkey, "Shift" }, "z", function () awful.util.spawn("xvkbd -xsendevent -text '\\[Control_L]\\[Shift_L]\\[Z]'") end), awful.key({ modkey, }, "y", function () awful.util.spawn("xvkbd -xsendevent -text '\\[Control_L]y'") end), awful.key({ modkey, }, "a", function () awful.util.spawn("xvkbd -xsendevent -text '\\[Control_L]a'") end), awful.key({ modkey, }, "s", function () awful.util.spawn("xvkbd -xsendevent -text '\\[Control_L]s'") end), awful.key({ modkey, }, "o", function () awful.util.spawn("xvkbd -xsendevent -text '\\[Control_L]o'") end), awful.key({ modkey, }, "f", function () awful.util.spawn("xvkbd -xsendevent -text '\\[Control_L]f'") end),