xdotool commands bound to key shortcuts doesnot wo

2020-05-24 06:08发布

问题:

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...

回答1:

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.