Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xdotool commands bound to key shortcuts doesnot work

I like VIM a lot and I wanted to use it's keybindings everywhere. There are many IDE plugins that can emulate this but I wanted more, maybe VIM keybindings in Minecraft? :D or VIM keybindings everywhere without the need to download any plugin.

I noticed that every single editor implements this keys: Home, End, Ctrl+End, Ctrl+Left, Ctrl+Backspace and so on...

I used these keys as a building blocks and I came up with this config for i3wm:

mode "VIM MODE NORMAL" {
    bindsym --release h exec "xdotool key --clearmodifiers Left"
    bindsym --release j exec "xdotool key --clearmodifiers Down"
    bindsym --release k exec "xdotool key --clearmodifiers Up"
    bindsym --release l exec "xdotool key --clearmodifiers Right"

    bindsym --release Shift H exec "xdotool key --clearmodifiers Home"
    bindsym --release Shift L exec "xdotool key --clearmodifiers End"
    bindsym --release Shift G exec "xdotool key --clearmodifiers ctrl+End"
    bindsym --release g exec "xdotool key --clearmodifiers ctrl+Home"

    bindsym --release u exec "xdotool key --clearmodifiers --repeat 5 Up"
    bindsym --release d exec "xdotool key --clearmodifiers --repeat 5 Down"

    bindsym --release b exec "xdotool key --clearmodifiers ctrl+Left"
    bindsym --release e exec "xdotool key --clearmodifiers ctrl+Right"

    bindsym --release Shift O exec "xdotool key --clearmodifiers Up End Return"; mode "delault"
    bindsym --release o exec "xdotool key --clearmodifiers End Return"; mode "default"
    bindsym --release Shift A exec "xdotool key --clearmodifiers End"; mode "default"
    bindsym --release Shift I exec "xdotool key --clearmodifiers Home"; mode "default"

    bindsym q mode "default"
    bindsym Escape mode "default"
}

bindsym Menu mode "VIM MODE NORMAL"

That code snippet works, but not in the way I want it to. If I don't use --release the code does not work at all, because of this keys do not repeat, so it is not possible to hold down on J and scroll down.

It seems to be a window focus issue. For some reason when I press keybindings, the window loses focus for some milliseconds and then it becomes focused again. This is most obvious in Firefox's Url Bar. I found this question asked years ago, which suggests adding one second delay until xdotool is executed, I could use this but second creates a huge input delay.

I have also tried other window managers and the hotkey daemon sxhkb but everything is exactly same...

like image 597
George Shalvashvili Avatar asked Jul 04 '18 20:07

George Shalvashvili


1 Answers

I had this same issue, and I realized that you have to tell xdotool to send keyup events for the keys in your keybindings. So for example:

bindsym h exec "xdotool keyup h; xdotool key"

Do that for every binding and I think it will work.

like image 124
lemonhuman Avatar answered Nov 19 '22 20:11

lemonhuman