-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fixes key handling for Windows. #172
Fixes key handling for Windows. #172
Conversation
* Add ToString implementation for SliderOption<T> * Add test case for SliderOption ToString with more complex class
* Add constructor overload to SliderOption * Adjust whitespace * Move tests to SliderOptionTests * Empty commit for CI
…rminal.Gui into BDisp-v2_vkeypacketsimulator-fix_3054
I disagree because it also work on Linux. Only some key bindings with shift aren´t recognized because of the SO itself but the all the rest work. |
VK_PACKET is literally a virtual key defined in winuser.h. There is no way for such a thing to be surfaced in curses. However if you mean the simulator can work on Linux that's a different point... that I fail to see the point of. I also don't see what api you'd use to map KeyCodes to codes chars without a Linux equivalent of MapVirtualKeyCode. Or, if you mean netdriver in Linux: how do we get the keyboard layout there? |
It's defined in dotnet as well in the ConsoleKey.Packet. |
Sorry, I wasn't clear. Let me try to be as clear as possible: Last year a developer submitted an Issue where key presses were not being handled correctly when using a Terminal.Gui app over RDP (gui-cs#2008). In investigating that issue you and @tznind learned about We learned that
The only OS that knows what In the fix (gui-cs#2032) a whole bunch of infrastructure code was introduced to try to decode these packets to solve for this use-case (users using Terminal.Gui apps over RDP). In addition to the infrastructure code ( As far as I can tell, none of the core Terminal.Gui maintainers (myself, you, and @tznind) regularly test the VK_PACKET support in a real scenario (e.g. over RDP).
The correct solution to all of this is: a) Create clear and easy to use instructions for setting up a system to routinely test Terminal.Gui over RDP (and any other use-case where I have a bad memory, and I apologize this didn't come to me before. But in 2004-ish I was partially responsible for adding
The RDP team had woken up to the fact that RDP didn't support Unicode and varying keyboard layouts well. Hence I am pretty sure I'm still confused on some details of all of this (e.g. the whole I hope that there's a similar API to |
Found this (which I haven't read yet, but wanted to document it): https://wiki.archlinux.org/title/Keyboard_input Note |
In Linux I really add code to test only the Simulator. |
new (13, VK.OEM_6, 0, '+'), // Oem6 | ||
new (13, VK.OEM_6, ConsoleModifiers.Shift, '*'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't send to the second TextView
on the Simulator |!"#$%&/()=?»>;:_
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what's going on here, but if I enable the "POR" keyboard and press the Shift-Oem6 key (labeled =
/+
on the ENG keyboard) I see this:
event: [KeyEventRecord(down,1,OEM_6,13,»,ShiftPressed)] [ConsoleKeyInfoEx(Key: 221 (Oem6) | Shift, KeyChar: » (187))]
event: [KeyEventRecord(up,1,OEM_6,13,»,ShiftPressed)] [ConsoleKeyInfoEx(Key: 221 (Oem6) | Shift, KeyChar: » (187))]
This is the correct behavior.
I can't send to the second TextView on the Simulator |!"#$%&/()=?»>;:_.
At this point, I do not care about the simulator. It serves no purpose right now other than to be a distraction. It doesn't actually simulate anything important. I am focused on fixing keyboard handling in a keyboard layout-independent way. That has nothing to with VK_PACKET
nor the simulator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is going to be a lot of work, like trying to resurrect a dead person. If you think it's the correct behavior because on the POR layout of your keyboard is right, then we cannot have an agreement here because on mine it isn't correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just pushed a quick change that will print the keyboard layout name on each keypress.
Note that GetKeybaordLayoutName
uses the current threadID and thus will only report the correct name if you did NOT change the keyboard layout after the debugging session was started.
Please
- Set your keyboard layout to POR
- debug UICatalog
- Press the
»
/«
key
Send what you see in the debug output. I see:
event: KBD: 00000816 [KeyEventRecord(down,1,OEM_6,13,«,0)] [ConsoleKeyInfoEx(Key: 221 (Oem6), KeyChar: « (171))]
event: KBD: 00000816 [KeyEventRecord(up,1,OEM_6,13,«,0)] [ConsoleKeyInfoEx(Key: 221 (Oem6), KeyChar: « (171))]
If I re-run the above, but first set my keyboard layout to ENG I see:
event: KBD: 00000409 [KeyEventRecord(down,1,OEM_PLUS,13,=,0)] [ConsoleKeyInfoEx(Key: 187 (OemPlus), KeyChar: = (61))]
event: KBD: 00000409 [KeyEventRecord(up,1,OEM_PLUS,13,=,0)] [ConsoleKeyInfoEx(Key: 187 (OemPlus), KeyChar: = (61))]
Both of these are correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the same as your.
event: KBD: 00000816 [KeyEventRecord(down,1,OEM_6,13,«,0)] [ConsoleKeyInfoEx(Key: 221 (Oem6), KeyChar: « (171))]
event: KBD: 00000816 [KeyEventRecord(up,1,OEM_6,13,«,0)] [ConsoleKeyInfoEx(Key: 221 (Oem6), KeyChar: « (171))]
event: KBD: 00000409 [KeyEventRecord(down,1,OEM_PLUS,13,=,0)] [ConsoleKeyInfoEx(Key: 187 (OemPlus), KeyChar: = (61))]
event: KBD: 00000409 [KeyEventRecord(up,1,OEM_PLUS,13,=,0)] [ConsoleKeyInfoEx(Key: 187 (OemPlus), KeyChar: = (61))]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good. So it's all working correctly now. Yay!
@tig do you want I merge this now? |
Feel free to merge my pr into your pr. But this is not ready to merge to v2_develop. If you merge into your pr, I'll keep doing more PRs to yours. |
I thought I was going crazy. Everything was working so well. Then I tried testing No matter what I did, I couldn't get a KeyDown for After pulling my hair out, I discovered that ShareX is somehow intercepting Sheesh. |
I have been unable to get any key events with Until we can get a setup that actually causes the code in |
@BDisp Windows driver seems to be working well now. Next we need to tweak NetDriver to do the same. Right now it's pretty broken. |
So I'll not merge it yet until you think it are ready to merge. |
Are you wiling to help with NetDriver? If so, merge now? If not, I'll try to get to NetDriver asap. |
I think you are in the right way and I would prefer to wait to see what is yours idea for this, if you don't mind. Thanks. |
@tig I don't know if this can help to play with VK_PACKET. This is in Python: This is in C#: |
None of these are "real world" setups. They are all simulations. If we want more simulated/forced scenarios, we could also use my own Media Center Controller which uses My latest research indicates that the VK_PACKET code gets lit up when using non-Windows RDP clients (like the one on an iPad) or AnyDesk. |
@BDisp have you ever seen NetDriver behave completely differently under WSL vs. Windows in regards to what key events it gets? |
I think so. What differences do you are getting? |
Ok I will see that tomorrow. |
Related, I think: https://devblogs.microsoft.com/dotnet/console-readkey-improvements-in-net-7/ |
It seems Net80 complicates it even more. |
Sorry @tig but |
|
@tig but this always worked well with the |
Sorry for I misunderstood badly and merge this, but I already saw the #173. |
All good. Back on track. |
Unless you are using a preview version with a new feature. |
Older versions would never connect for me. I'm running Version 17.9.0 Preview 2.1 |
@BDisp - see this: dotnet/runtime#96490 (comment) I just did a test: I commented out if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows) {
//IsWinPlatform = true;
//try {
// NetWinConsole = new NetWinVTConsole ();
//} catch (ApplicationException) {
// // Likely running as a unit test, or in a non-interactive session.
//}
} Theoretically, this should have made Windows work just like WSL. And for KEYBOARD it does! To debug further, based on Adam's question, I tried this: if ((mode & ENABLE_VIRTUAL_TERMINAL_INPUT) < ENABLE_VIRTUAL_TERMINAL_INPUT) {
//mode |= ENABLE_VIRTUAL_TERMINAL_INPUT;
if (!SetConsoleMode (_inputHandle, mode)) {
throw new ApplicationException ($"Failed to set input console mode, error code: {GetLastError ()}.");
}
} By not enabling But, mouse no longer works. Do you know why Mouse does not work on Windows with Before I reply to Adam, I'd like to understand the history better. Not sure if you know or not. Thanks. |
@tig - Without the |
@BDisp this is still a work in progress.
I broke ENTER key handling in Textview but this is now on the right track, i think.
I need to take a break, so I'm submitting this before it's really ready.
I did not touch the VKeySimulator because A ton of the underlying code is simply wrong and needs to be redone.
Note that the whole VK_Packet stuff is only relevant on Windows (and perhaps only WindowsDriver). the Scenario should NOT even attempt to work on Linux IMO.