Is there a way to make simultaneous key presses into a keybinding, e.g. for the keys w, e, f, when pressed within 0.05 seconds of each other, to trigger a command?
更具体:
If w, e, f are pressed within 0.05 seconds of each other, then upon the pressing of the last one, XMonad should trigger said command. XMonad should also have intercepted the three keys so that they are not superfluously sent to the focused window.
否则(如果在 0.05 秒时间段内至少没有按下其中一个)XMonad 应像往常一样将按键发送到聚焦窗口。
My goal in this is to use w, e, f to "Escape" into a vim-like "Normal Mode", a XMonad.Actions.Submap (submap).
更新为failed方法,以防任何人都可以找到解决方法:
I attempted to implement this using submaps, so that, for example, if you pressed w you would end up in chord_mode_w
, if you pressed e from there you would end up in chord_mode_we
, and if you pressed f from there you would finally end up in normal_mode
, for instance. The implementation was very messy: I included, in my main keybindings, something like:
("w", spawn "xdotool key <chord_mode_w_keybinding> ; sleep 0.05 ; xdotool key <abort_keybinding>")
(chord_mode_w_keybinding, chord_mode_w)
for detecting w (the rest would be similar), along with (incomplete) submaps such as:
chord_mode_w = submap . mkKeymap c $
[
("e", chord_mode_we )
, ("f", chord_mode_wf )
, (abort_keybinding, pasteString "w")
-- in order for the submap to not eat all other letters,
-- would need to include all mappings like:
, ("a", pasteString "wa")
, ("b", pasteString "wb")
...
]
chord_mode_we = submap . mkKeymap c $
[
("f", normal_mode )
, (abort_keybinding, pasteString "we")
-- in order for the submap to not eat all other letters,
-- would need to include all mappings like:
, ("a", pasteString "wea")
, ("b", pasteString "web")
...
]
chord_mode_wf = submap . mkKeymap c $
[
("e", normal_mode )
, (abort_keybinding, pasteString "wf")
-- in order for the submap to not eat all other letters,
-- would need to include all mappings like:
, ("a", pasteString "wfa")
, ("b", pasteString "wfb")
...
]
一个完整的实现显然会非常混乱,但理论上应该让我normal_mode
如果我在 0.05 秒内按下“wef”,则中止并键入字符,否则。然而,有两个问题:
pasteString
(以及其他粘贴功能XMonad.Util.Paste
) 对于正常打字来说太慢
我最终会在normal_mode
即使我将中止延迟设置得更高,也只有一小部分时间。不确定这背后的原因。
(我使用的原因pasteString
当中止而不是产生另一个时xdotool
的输出是xdotool
将重新触发其中之一chord_mode_w_keybinding
, chord_mode_e_keybinding
, chord_mode_f_keybinding
,回到主键绑定,让我无限期地回到和弦模式。)