How to bind double tapping the shift key in tmux

command linekeyboardterminaltmux

i spent some time yesterday trying to figure out how i can bind a double tap -esque key binding for tmux, and made some progress, but still incomplete.

i am hoping to maximize/minimize a pane within a tmux window by double tapping the shift key. even better if i can granularly map it to the left shift key and have double tapping the right shift key perform a different key binding.

while doing some research on how to do this i came across this unix/linux stackexchange q&a. the person who asked that question is essentially asking the same thing i am but on a gnu+linux platform and not a darwin+bsd platform ie. macos.

in that unix/linux q&a the op who provides the accepted answer recommends using xcape to map a custom binding for xterm (if i understand correctly), and i believe xcape is tied to X11 window manager, and i'm using Alacritty as my terminal emu along with Aqua as my desktop environment, so i don't believe using xcape is a viable solution on macos. i am aware of karabiner-elements for setting custom key mappings on macos, which i have done for several keys, but i don't think i'd have to set that up (but could be wrong) as this binding is specific to my term emu.

it seems either my tmux mappings are not correct or alacritty is not passing the mapping to tmux in order to perform the mapping. this is where things get confusing for me.

a couple of things i have tried within my tmux.conf

set-option prefix2 "f11" # WORK!!!
bind-key "f11" resize-pane -Z # double tap f11 (requires holding fn key on mbp keyboard)

when i set the prefix2 with the below setting

set-option prefix2 "C-S-M"
bind C-S-M display "ctrl+shift+meta pressed"

i do not see the message flashed within my tmux status bar.

i have other key bindings in tmux that use the shift key with arrow keys, so i know it's not a problem with the shift key, so i'm confused as to which program i don't have configured properly.

i have my alacritty.yml config file hosted within my dotfiles repo, and my tmux.conf is hosted within the same repo but i have pasted the important parts above. please excuse my ignorance if i'm forgetting something trivial.

Best Answer

Binding C-S-M won't work for two reasons. Firstly there is no key S-M - M is already shifted. Secondly, there is are no uppercase control keys. See https://github.com/tmux/tmux/wiki/Modifier-Keys#limitations-of-ctrl-keys.

Your best bet for keys that the terminal cannot send are to map them to a key that the terminal can send (like F11 or C-F2) using xbindkeys or similar program.

You don't need to change prefix to make double pressing a key work, you can do it with key tables, for example something like:

bind -Tmytable F11 lsk
bind -Troot F11 switchc -Tmytable
Related Question