-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Control+Space not sent to program running in terminal #15939
Comments
Note, I see this issue was brought up before (and apparently solved): #2865. Either this is a slightly different issue or perhaps it broke again. |
Are you running a Windows version of neovim, or in WSL/cygwin/msys/git bash, or over ssh of some sort/? Those can all be complicating factors here. |
In pwsh (PSReadline module), for example, |
@jfedorkiw inside nvim session type |
I'm having the same problem with several CTRL combinations. In testing neovim with the exact same configuration in WSL2, Powershell Core, and nvim-qt: WSL2: CTRL-space works, CTRL-[ (remapped, not used as escape) doesn't work, CTRL-9 doesn't work (seems to just come through as 9) I'm on the latest WT preview and Windows 11 insider beta. |
I'm just running nvim through PowerShell inside the terminal app. The problem is also the same when using "Command Prompt" inside terminal. Note that it if I use nvim-qt, which launches NeoVim in it's own window, Ctrl-Space works as expected (sending the escape character). Also - the same problem exists in Vim.
In this case I opened up the terminal and hit Control+Space to see what was being sent: Here is the text copy & pasted for your debugging pleasure:
As a Breakdown here is what I see happen as I execute the key combination: Press Control:
Press Space:
And then when I release Control you get the trailing
On the left side of the screen, when I hit Control+Space it results in a Space character showing up (as if I had just pressed space) Interestingly, if I hit Control+Space on the RIGHT side of the window, where it outputs the debug text, it sends the NUL (␀) character (which I believe is what Control+Space is supposed to send). @zcobol
Note the mapped vim-wiki functionality doesn't work. Also, as mentioned above, these key combinations do work as expected when running nvim-qt. Thank-you all for your support in this matter, John |
that all looks right |
This might be neovim/neovim#19575 |
I believe the problem is that when you hit Control+Space nvim is expecting a different character. As a similar example, in the terminal when you hit Control+F you get a different set of characters:
I believe it expects the "Nul" character, but I'm not sure 100% sure about this. Im not sure i there is an easy way to verify this (is it possible to emulate sending a specific character to the terminal ?). As an interesting side note (and as noted above) when you type Control+Space in the right side of the split debug terminal you actual do get the Nul character (␀). For some reason that side of the terminal does something different when you hit space while having control pressed. |
@jfedorkiw
Only insert mode was mapped since the bug was filed against For each When using the wt.exe only The mapping is correct and it does come from When using The mapping seems to work okay when using the GUI version of neovim: |
Here's a thought - what keyboard layout are you using? |
I'm using a QWERTY Keyboard. It's not clear to me there is agreement on what the core of the bug is. It might be useful to clarify. I'm under the impression the core problem is that the terminal isn't passing along a special key-character when the Control+Space combination is pressed. The confusion then comes from the fact that presumably this is working on some folks setups but not mine. It could also be the case that you don't agree the terminal should be converting Control+Space into a special key press (which seems reasonable as this clearly doesn't seem to be well defined behaviour). In that case the "fix" may be more of a feature request to allow users to bind custom key-combinations to specific key codes. John |
There's definitely no disagreement there. The trick here is trying to find what layer in particular is losing the keystroke. What we established up in #15939 (comment) is
Now, part of the problem here is probably just that I don't totally get nvim, sorry about that. I've put the following in " vim.keymap.set({'i', 'n', 'v', 'o'}, '', '', {noremap=true})
vim.keymap.set('i', 'A', 'foo', {noremap=true})
vim.keymap.set('i', '<C-Space>', 'bar', {noremap=true}) Though, when I do a Maybe another part of the problem that could be complicating this is using WSL So I'd love to find out is where in the stack the key sequence is getting lost. Is the key making it all the way through conhost? Is conhost sending something to nvim that they're throwing away? |
@zadjii-msft I believe this is a conhost issue. I can reproduce the problem with a simple app that reads characters with When I press Ctrl+Space I can see it generates the terminal/src/terminal/input/terminalInput.cpp Lines 623 to 629 in cc2ba53
But that terminal/src/host/inputBuffer.cpp Lines 817 to 820 in cc2ba53
That key event then gets process by the Lines 234 to 244 in cc2ba53
But the Two possible solutions:
Frankly both of those options seem a bit messy, so I'm hoping someone that understands the code base might have a better suggestion, but at least that's a starting point. Btw, I'm not absolutely certain this is the same issue that the OP is seeing in vim, but it seems likely. |
Ah I see, that makes sense, since I made the change to the
As the culprit, I'll try to fix this issue then. I think the 2nd suggestion is better, because there's no 0 value for the virtual key on any keyboard (the minimum is 1 with It might be interesting how it used to work in conhost v1: #define EITHER_CTRL_PRESSED (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)
#define EITHER_ALT_PRESSED (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)
#define MOD_PRESSED (SHIFT_PRESSED | EITHER_CTRL_PRESSED | EITHER_ALT_PRESSED)
DWORD ConsKbdState[] = {
0,
SHIFT_PRESSED,
EITHER_CTRL_PRESSED,
SHIFT_PRESSED | EITHER_CTRL_PRESSED,
EITHER_ALT_PRESSED,
SHIFT_PRESSED | EITHER_ALT_PRESSED,
EITHER_CTRL_PRESSED | EITHER_ALT_PRESSED,
SHIFT_PRESSED | EITHER_CTRL_PRESSED | EITHER_ALT_PRESSED
};
#define KEYEVENTSTATE_EQUAL_WINMODS(Event, WinMods)\
((Event.Event.KeyEvent.dwControlKeyState & ConsKbdState[WinMods]) && \
!(Event.Event.KeyEvent.dwControlKeyState & MOD_PRESSED & ~ConsKbdState[WinMods]))
NTSTATUS GetChar(...)
{
// ...
SHORT sTmp = VkKeyScanW(0);
// ...
if ((LOBYTE(sTmp) == Event.Event.KeyEvent.wVirtualKeyCode) && KEYEVENTSTATE_EQUAL_WINMODS(Event, HIBYTE(sTmp)))
{
// This really is the character 0x0000
*pwchOut = Event.Event.KeyEvent.uChar.UnicodeChar;
return STATUS_SUCCESS;
}
// ...
} As far as I can tell the intention of the original code is identical to what I now wrote. But the original code was flawed as far as I can tell, because the Was the original v1 behavior correct? |
@lhecker FWIW, I don't think this was broken by any of your recent changes. I've tested in my Window 10 inbox conhost (which I think is several years old), and it was already not working in that version. |
Just to note that I rechecked this behaviour and it seems to have started working for me. As noted on the older issue for this, I saw no keycode for ctrl+space. Now both ctrl+space and ctrl+single quote generate a null which maps to The only thing that seems to have changed since I last tested is the Windows version number: 10.0.22621.1778 didn't work, 10.0.22621.2283 does. |
@j4james I terminal/src/terminal/input/terminalInput.cpp Lines 488 to 494 in cc2ba53
Press terminal/src/terminal/input/terminalInput.cpp Line 740 in cc2ba53
|
@lonnywong If you're testing in Windows Terminal rather than conhost/openconsole then you're dealing with conpty, which adds another layer of redirection. Windows Terminal forwards the individual keyup/keydown events over conpty as win32-input sequences. Those sequences are later received by conhost and converted back into keyboard events. And those keyboard events are then processed by the conhost version of the |
@j4james Thanks. Pressing keys in Lines 234 to 244 in cc2ba53
terminal/src/host/inputBuffer.cpp Lines 817 to 820 in cc2ba53
|
@zadjii-msft @lhecker @j4james Can you help to review #16298 ? Thanks. |
…16298) Converts null byte to specific input event, so that it's properly delivered to the program running in the terminal. Closes microsoft#15939
Windows Terminal version
1.17.11461.0
Windows build number
10.0.22621.2134
Other Software
NeoVim v0.9.1
Steps to reproduce
Inside init.lua:
NOTE: This Is also the case in VIM as well. It doesn't seem like the Control+Space character is making it to whatever is running in the terminal
Expected Behavior
I expect Control+Space character to make it to the program running in the terminal
Actual Behavior
When you hit Control+Space there is no reaction to the program running in the terminal. The command does not appear to be sent.
The text was updated successfully, but these errors were encountered: