xdotool commands bound to key shortcuts doesnot work

▼魔方 西西 提交于 2020-01-12 03:59:22

问题


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.



来源:https://stackoverflow.com/questions/51180405/xdotool-commands-bound-to-key-shortcuts-doesnot-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!