Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

key bindings in windows (mapping Ctrl+Space) #1703

Open
damnskippy opened this issue Oct 25, 2018 · 59 comments
Open

key bindings in windows (mapping Ctrl+Space) #1703

damnskippy opened this issue Oct 25, 2018 · 59 comments

Comments

@damnskippy
Copy link

Using alacritty (downloaded from the appveyor link) on windows and have some issues/questions about key bindings.

  1. bash shortcuts using Alt key are not working - is this expected?
    I added a few mappings to the config file that gets me some of what I most commonly use, but however I still miss several other important ones that I don't know how to map (Alt+. for instance, and others).
    Should this work out of the box, or if not, can a canned list of such mappings be made available for those who might want to add it to their configs optionally.
    One I sorely miss and don't know how to map is Ctrl+Alt+e which binds to expanding aliases.
  - { key: D,        mods: Alt,     chars: "\x1bd"                       }
  - { key: B,        mods: Alt,     chars: "\x1bb"                       }
  - { key: F,        mods: Alt,     chars: "\x1bf"                       }
  1. In tmux I use Space as my prefix key.
    set -g prefix C-Space
    I've tried different things (blindly) in the config file and couldn't get this to work.
    Any pointers on how to achieve this mapping?

Off topic, but on windows, alacritty doesn't honor any of the command line arguments for me. I've seen other folks refer to using this even on windows, so somehow it is specific to my setup I assume. i.e. if I run alacritty.exe -vvv it spawns the terminal but there is no debug output, or if I do alacritty.exe --help the command just returns without any output.

Thanks!

@damnskippy
Copy link
Author

Thank you @zacps for all the effort you've put into the windows port!

@zacps
Copy link
Contributor

zacps commented Oct 25, 2018

Thanks!

Regarding the console output are you using a build from a7e59d39 or later? There was a change made which should fix console output.

Keybindings are not something I've tested much. I don't know how 'special' actions like expanding aliases are triggered.

It's possible that this might need to wait for #1661, because currently all input to Alacritty has to pass through:

Alacritty => WinPTY => CONHOST(cmd) => Shell(User specified)

And if any part of that chain doesn't understand the input it'll probably just get dropped (CONHOST being the worst offender).

I'd suggest trying these things in a bare wsl prompt to see if they work first, then we can go from there.

@damnskippy
Copy link
Author

Not being able to map Control+Space kills me as that's my tmux prefix, and I just cannot get it to work (even in bare wsl). Not sure if this is Windows specific, or if I am just not setting up the mapping correctly. I've tried this to no avail:
- { key: Space, mods: Control, chars: "\x00" }

I managed to get Alt+. working using the mapping:
- { key: Period, mods: Alt, chars: "\x1b." }

BTW, I moved up to the latest rev from Appveyor and that resolved the console output issue! Thanks again.

@damnskippy
Copy link
Author

Found a few past references to using Ctrl+Space, most of them duped to #99, however the popular solution referenced in there doesn't work for me on Windows, it's the one I referenced above, but I'll include the mapping below again.
- { key: Space, mods: Control, chars: "\x00" }

Not sure if this is Windows specific or my setup specific. Would be great if someone can test this out in their setup..

@zacps
Copy link
Contributor

zacps commented Oct 27, 2018

If you can't get it to work in bare wsl it's extremely unlikely we'll be able to solve it in alacritty (Might be worth creating an issue in Microsoft/console).

You're welcome to keep investigating this but I'm probably not going to give it much attention anytime soon.

@zacps zacps added the A - deps label Oct 27, 2018
@fculpo
Copy link

fculpo commented Oct 28, 2018

Not sure if it's related, but Alt Gr is not working in Alacritty (eg. can't type @ on Azerty)
Works fine in other terminals

@zacps
Copy link
Contributor

zacps commented Oct 28, 2018

@fculpo See #1681

@damnskippy
Copy link
Author

If you can't get it to work in bare wsl it's extremely unlikely we'll be able to solve it in alacritty

I can confirm that this works as expected in cmd and powershell running wsl. i.e. I'm able to set C-Space as my tmux prefix key and it works without any issues.

I assume this is what you were referring to when you say "bare wsl"?

@damnskippy
Copy link
Author

damnskippy commented Oct 28, 2018

Seems specific to Windows alacritty given #99 seems to resolve for other platform(s).
FWIW, pretty easy to repro in a couple of steps:

  1. run tmux in bash
  2. set prefix by doing: tmux set -g prefix C-Space
  3. now type C-space followed by % - this if it works successfully will split the terminal into two vertical panes, otherwise it would enter the % or Space character literally as it does on Windows alacritty.

@damnskippy
Copy link
Author

Ran with --print-events to see what the key press events captured by alacritty.
Looks like alacritty is picking up the key presses fine but they're potentially getting dropped on the floor somewhere without getting passed on to bash/tmux?
Either that, or the mapping in alacritty.yml is not correct/working.

glutin event: DeviceEvent { device_id: DeviceId(DeviceId(462556243)), event: Key(KeyboardInput { scancode: 29, state: Pressed, virtual_keycode: Some(LControl), modifiers: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } }) }
glutin event: WindowEvent { window_id: WindowId(WindowId(0x12d0f6e)), event: KeyboardInput { device_id: DeviceId(DeviceId(0)), input: KeyboardInput { scancode: 29, state: Pressed, virtual_keycode: Some(LControl), modifiers: ModifiersState { shift: false, ctrl: true, alt: false, logo: false } } } }
glutin event: DeviceEvent { device_id: DeviceId(DeviceId(462556243)), event: Key(KeyboardInput { scancode: 57, state: Pressed, virtual_keycode: Some(Space), modifiers: ModifiersState { shift: false, ctrl: true, alt: false, logo: false } }) }
glutin event: WindowEvent { window_id: WindowId(WindowId(0x12d0f6e)), event: KeyboardInput { device_id: DeviceId(DeviceId(0)), input: KeyboardInput { scancode: 57, state: Pressed, virtual_keycode: Some(Space), modifiers: ModifiersState { shift: false, ctrl: true, alt: false, logo: false } } } }
glutin event: WindowEvent { window_id: WindowId(WindowId(0x12d0f6e)), event: ReceivedCharacter(' ') }
glutin event: Awakened
glutin event: DeviceEvent { device_id: DeviceId(DeviceId(462556243)), event: Key(KeyboardInput { scancode: 57, state: Released, virtual_keycode: Some(Space), modifiers: ModifiersState { shift: false, ctrl: true, alt: false, logo: false } }) }
glutin event: WindowEvent { window_id: WindowId(WindowId(0x12d0f6e)), event: KeyboardInput { device_id: DeviceId(DeviceId(0)), input: KeyboardInput { scancode: 57, state: Released, virtual_keycode: Some(Space), modifiers: ModifiersState { shift: false, ctrl: true, alt: false, logo: false } } } }
glutin event: DeviceEvent { device_id: DeviceId(DeviceId(462556243)), event: Key(KeyboardInput { scancode: 29, state: Released, virtual_keycode: Some(LControl), modifiers: ModifiersState { shift: false, ctrl: true, alt: false, logo: false } }) }
glutin event: WindowEvent { window_id: WindowId(WindowId(0x12d0f6e)), event: KeyboardInput { device_id: DeviceId(DeviceId(0)), input: KeyboardInput { scancode: 29, state: Released, virtual_ke

@damnskippy damnskippy changed the title key bindings in windows key bindings in windows (mapping Ctrl+Space) Oct 28, 2018
@damnskippy
Copy link
Author

Still not sure how to map ctrl+space in windows, but closing this issue since there doesn't seem any open action here.

@gaving
Copy link

gaving commented Jan 7, 2020

Burned by this on Windows, sad to see this closed. 😭

@jsinkers
Copy link

@damnskippy Did you ever happen to solve this issue? Currently having the same problem (but trying to use ctrl+space in Vim rather than in tmux). I see the Ubuntu WSL app handles Ctrl+space fine, as well as WSLtty, but sadly no luck in Ubuntu. Temporary fix for me will be to remap my Ctrl+space in Windows to something else (thankfully I don't use Ctrl+space for much) but far from ideal.

@Shooooooooo
Copy link

+1. It's a bummer for Emacs users. ctrl+space is the equivalent of v in vim.

@pmhoudry
Copy link

Indeed ! So sad C-Space does not work since in emacs its such an important key combination... I wish it would work so I would not be forced to use microsoft terminal.

@sudonym1
Copy link

sudonym1 commented Jul 1, 2020

Could we get this issue reopened please? ctrl+space is working fine in wsl, with windows terminal, powershell, and cmd.exe.

@kchibisov
Copy link
Member

Show us alacritty --print-events when you press ctrl + space? In general we can't do much about issues on Windows, since it's not up to us, but up to WinPty/Conpty.

@sudonym1
Copy link

sudonym1 commented Jul 1, 2020

Alacritty-14440.log

In the above I pressed ctrl+space, ctrl+c, ctrl+d

Thanks for taking a look.

@Akaito
Copy link

Akaito commented Jul 14, 2020

#1703 (comment)
User damnskippy's comment above worked for me with Alacritty on Win10. In case it's relevant, I'm launching Alacritty into WSL with

shell:
  program: bash
  args:
    - -c tmux

For the lazy, damnskippy's fix was this: - { key: Space, mods: Control, chars: "\x00" }

I also see some mentions of configuring tmux like

set -g prefix C-Space
unbind C-Space
bind C-Space send-prefix

That middle "unbind" line is new to me, and may or may not be important for your setup.

Just in case there's some other mystery config I have interacting with this that I'm not aware of, all my configs are here: https://github.com/Akaito/configfiles

@zacharied
Copy link
Contributor

zacharied commented Aug 3, 2020

Today I changed my shell on a remote server to ZSH (probably not related but that was the last thing I did) and my Control-Space binding completely stopped working. I tried to apply damnskippy's fix but to no avail. In fact, it would seem that Alacritty is not detecting anything when I press Control-Space. I can change the chars in that fix to any sequence of characters, but no matter what I do, pressing Control-Space just yields ^\ in the terminal.

I have alacritty running with shell.program: wsl. The keybinding works with no issues or configuration whatsoever when I try it in the default WSL terminal.

I cannot run alacritty --print-events as it errors out with Failed to initalize any backend!.

I am truly at a loss as to how this started happening, but I can provide any relevant info if needed.

@sharksforarms
Copy link

Ctrl + Space is not getting passed for me.

Host: Windows

ssh'ing to ubuntu vm, shell is bash and the mapping shown in previous post makes no difference. showkey -a doesn't show anything being pressed

@dhruvasagar
Copy link

This is broken, the fix does not work for me either. The interesting thing is the exact same setup / configurations work perfectly fine with the latest Windows Terminal so it's surely something in Alacritty itself.

@chrisduerr
Copy link
Member

If Alacritty's output contains ReceivedCharacter('\u{0}') when running alacritty --print-events | grep "ReceivedCharacter", then this is a Windows bug.

If it doesn't contain that for you, please let me know.

@sharksforarms
Copy link

I am getting the following when doing Control + Space:

[2020-08-07 09:42:46.458983200] [INFO] glutin event: WindowEvent { window_id: WindowId(WindowId(0x620714)), event: ReceivedCharacter(' ') }

@pdckxd
Copy link

pdckxd commented Oct 24, 2021

Unfortunately, all above solutions doesn't work from my side. But I finnally find this is caused by a bug of openssh-windows client. microsoft/terminal#2865 (comment)

I managed to build openssh-windows with this fix. Now alacritty and windows terminal can send "ctrl - space" through ssh.exe to remote server ("Ctrl+Space" prefix in tmux works as expected)

prefix setting in tmux

set -g prefix C-Space
unbind C-Space
bind C-Space send-prefix

don't forget to add below config to alacritty.yaml file at first. Otherwise above fix won't work for alacritty.

- { key: Space, mods: Control, chars: "\x00" }

@cypres-it
Copy link

I have this issue under windows when ssh'ing to a linux box and using emacs. There set-mark-command is bound per default to Ctrl-Space, but it does not work in alacritty. Instead just a space is inserted at the current cursor position. This happens also without using tmux/screen.

@llinfeng
Copy link

Just to be clear, the advertised - { key: Space, mods: Control, chars: "\x00" } solution should go as the following in alacritty.yml:

key_bindings:
    - { key: Space, mods: Control, chars: "\x00" }

@serranomorante
Copy link

Just to be clear, the advertised - { key: Space, mods: Control, chars: "\x00" } solution should go as the following in alacritty.yml:

key_bindings:
    - { key: Space, mods: Control, chars: "\x00" }

Your comment just saved my life.

@rafa-thayto
Copy link

Just to be clear, the advertised - { key: Space, mods: Control, chars: "\x00" } solution should go as the following in alacritty.yml:

key_bindings:
    - { key: Space, mods: Control, chars: "\x00" }

Thank you so much!

@jimporter
Copy link

Unfortunately, all above solutions doesn't work from my side. But I finnally find this is caused by a bug of openssh-windows client. microsoft/terminal#2865 (comment)

I managed to build openssh-windows with this fix. Now alacritty and windows terminal can send "ctrl - space" through ssh.exe to remote server ("Ctrl+Space" prefix in tmux works as expected)

Another way to get a working ssh on Windows (if you don't want to rely on MS's OpenSSH port) is to use the MSYS2 ssh, which most users likely already have: it's distributed alongside Git for Windows in C:\Program Files\Git\usr\bin. The MSYS2 port is nice because it's pretty much the same SSH as you'd get on Linux, so it's battle-tested. While I appreciate that MS is trying to provide nice things like a native OpenSSH port, it's just not reliable enough (yet).

I've been using that with the recent change to support newer conpty.dll versions, and it works perfectly as far as I can tell. (At least on Windows 10, you really need the conpty.dll fix to do it this way. Without it, I got extraneous \ characters in my terminal.)

@georgeanderson
Copy link

Yes, another one here benefited by this. Thank you!

@vanillaSprinkles
Copy link

@jimporter - appreciate your your build of alacritty ( cmentioned in #6994 ) - couldnt get the \ chars removed (on my win10 system) using any conpty i found in the wild. Looks like it'll be posted in to https://www.nuget.org/packages?q=conpty at some point in the future so I'll keep waiting and using putty instead.

The keybind did work in good ol emacs using git-ssh but not ms's built in agent

@jimporter
Copy link

@jimporter - appreciate your your build of alacritty ( cmentioned in #6994 ) - couldnt get the \ chars removed (on my win10 system) using any conpty i found in the wild. Looks like it'll be posted in to https://www.nuget.org/packages?q=conpty at some point in the future so I'll keep waiting and using putty instead.

I just used the openconsole.exe and conpty.dll from WezTerm's Windows builds: https://wezfurlong.org/wezterm/install/windows.html, and it worked ok for me.

@vanillaSprinkles
Copy link

@jimporter - appreciate your your build of alacritty ( cmentioned in #6994 ) - couldnt get the \ chars removed (on my win10 system) using any conpty i found in the wild. Looks like it'll be posted in to https://www.nuget.org/packages?q=conpty at some point in the future so I'll keep waiting and using putty instead.

I just used the openconsole.exe and conpty.dll from WezTerm's Windows builds: https://wezfurlong.org/wezterm/install/windows.html, and it worked ok for me.

Thanks! i did not realize that openconsole.exe was also needed; dropped it and conpty.dll side by side with the alacritty.exe build and the ctrl+space is working and no funky \ chars. Also thanks for the wezterm url!

@Tal500
Copy link

Tal500 commented Sep 23, 2023

@jimporter - appreciate your your build of alacritty ( cmentioned in #6994 ) - couldnt get the \ chars removed (on my win10 system) using any conpty i found in the wild. Looks like it'll be posted in to https://www.nuget.org/packages?q=conpty at some point in the future so I'll keep waiting and using putty instead.

I just used the openconsole.exe and conpty.dll from WezTerm's Windows builds: https://wezfurlong.org/wezterm/install/windows.html, and it worked ok for me.

Thanks! i did not realize that openconsole.exe was also needed; dropped it and conpty.dll side by side with the alacritty.exe build and the ctrl+space is working and no funky \ chars. Also thanks for the wezterm url!

With this advice, together with updating OpenSSH version for Windows as instructed here - https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH - I managed to finally get "CTRL+Space" to work even over SSH, together with mouse event forwarding.

So it would be nice to update in the readme the following steps for getting it to work (summarizing everyone up):

  1. Get the latest dev Alacritty version
  2. Copy the both "conpty.dll" and "OpenConsole.exe" from https://github.com/wez/wezterm/tree/main/assets/windows/conhost to Alacritty binaries dir
  3. Update OpenSSH to version >= 8.9 either by having "Windows Insider Builds" or by winget as in https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH
  4. Configure - { key: Space, mods: Control, chars: "\x00" } under key_bindings configurations of Alacritty, and this is the way to do this in the new DEV TOML configurations:
[[keyboard.bindings]]
chars = "\u0000"
key = "Space"
mods = "Control"

Didn't open the issue by myself, but this steps fully closes the issue.

@hagaigold
Copy link

hagaigold commented Oct 7, 2023

Something is different with Alacrity on Windows 10.
With 4 terminals, testing wsl with showkey -a- Alacrity is the only one show 32 0040 0x20 also for CTRL+Space.

image

@hagaigold
Copy link

Another test- cmd.exe with clink echo :

image

@Amleto
Copy link

Amleto commented Nov 1, 2023

I have the same problem with my usage on windows 10. Normally I run git-bash, but I see the problem in nvim whether starting from powershell, cmd, wezterm, win terminal, alacritty regardless of shell. ctrl+space does work when using the nvim gui.

On wezterm I could fix this with { key = ' ', mods = 'CTRL', action = act.SendKey{ key = ' ', mods = 'CTRL' } }.

I've tried the \x00 map. It changes behaviour from Space (plain space, no modifier) being received in nvim to nothing being received.

@Tal500
Copy link

Tal500 commented Nov 1, 2023

I have the same problem with my usage on windows 10. Normally I run git-bash, but I see the problem in nvim whether starting from powershell, cmd, wezterm, win terminal, alacritty regardless of shell. ctrl+space does work when using the nvim gui.

On wezterm I could fix this with { key = ' ', mods = 'CTRL', action = act.SendKey{ key = ' ', mods = 'CTRL' } }.

I've tried the \x00 map. It changes behaviour from Space (plain space, no modifier) being received in nvim to nothing being received.

@hagaigold @Amleto Did you try my solution? I reefer to:

@jimporter - appreciate your your build of alacritty ( cmentioned in #6994 ) - couldnt get the \ chars removed (on my win10 system) using any conpty i found in the wild. Looks like it'll be posted in to https://www.nuget.org/packages?q=conpty at some point in the future so I'll keep waiting and using putty instead.

I just used the openconsole.exe and conpty.dll from WezTerm's Windows builds: https://wezfurlong.org/wezterm/install/windows.html, and it worked ok for me.

Thanks! i did not realize that openconsole.exe was also needed; dropped it and conpty.dll side by side with the alacritty.exe build and the ctrl+space is working and no funky \ chars. Also thanks for the wezterm url!

With this advice, together with updating OpenSSH version for Windows as instructed here - https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH - I managed to finally get "CTRL+Space" to work even over SSH, together with mouse event forwarding.

So it would be nice to update in the readme the following steps for getting it to work (summarizing everyone up):

1. Get the latest dev Alacritty version

2. Copy the both "conpty.dll" and "OpenConsole.exe" from https://github.com/wez/wezterm/tree/main/assets/windows/conhost to Alacritty binaries dir

3. Update OpenSSH to version >= 8.9 either by having "Windows Insider Builds" or by winget as in https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH

4. Configure `- { key: Space, mods: Control, chars: "\x00" }` under `key_bindings` configurations of Alacritty

Didn't open the issue by myself, but this steps fully closes the issue.

@Amleto
Copy link

Amleto commented Nov 1, 2023

I dont understand how openssh changes would help when I'm not using ssh for anything. I'm not using wsl.

I did try it, though, and it made no difference

@Tal500

@Tal500
Copy link

Tal500 commented Nov 1, 2023

I dont understand how openssh changes would help when I'm not using ssh for anything. I'm not using wsl.

I did try it, though, and it made no difference

@Tal500

Did you then fully do steps 1, 2 and 4?

@Amleto
Copy link

Amleto commented Nov 1, 2023

don't know precisely what you refer to as 'latest dev'. I am using the 0.12.3 release. Yes, I did 1,2,4 (actually I just copied the files from my wezterm install)

@kchibisov
Copy link
Member

0.12.3 won't work with the suggested instruction, only manual building will work for now.

@Tal500
Copy link

Tal500 commented Nov 1, 2023

don't know precisely what you refer to as 'latest dev'. I am using the 0.12.3 release. Yes, I did 1,2,4 (actually I just copied the files from my wezterm install)

The requirement for the latest dev version is very important, since the official releases didn't merge yet the PR #6994

@Amleto
Copy link

Amleto commented Nov 1, 2023

I cloned the repo and built it. I copied the binaries from wezterm into the build output dir.
I updated config to toml, but "\x00" is invalid so I changed it to "\u0000".

[[key_bindings]]
key = "Space"
mods = "Control"
chars = "\u0000"

This still does not make C-Space be detected

@Tal500
Copy link

Tal500 commented Nov 1, 2023

I cloned the repo and built it. I copied the binaries from wezterm into the build output dir. I updated config to toml, but "\x00" is invalid so I changed it to "\u0000".

[[key_bindings]]
key = "Space"
mods = "Control"
chars = "\u0000"

This still does not make C-Space be detected

This is the right setup, updating my original comment as well:

[[keyboard.bindings]]
chars = "\u0000"
key = "Space"
mods = "Control"

Yovach added a commit to Yovach/dotfiles that referenced this issue Jan 28, 2024
@adonespitogo
Copy link

Here's my setup:

[keyboard]
bindings = [
	{key = "Space", mods = "Control", chars = "\u0000"},
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests