Figure out VK_PACKET
/ConsoleKey.Packet
and build support for it
#3119
Labels
design
Issues regarding Terminal.Gui design (bugs, guidelines, debates, etc...)
Milestone
Last year a developer submitted an Issue where key presses were not being handled correctly when using a Terminal.Gui app over RDP (#2008). In investigating that issue @BDisp and @tznind learned about
ConsoleKey.Packet
.We learned that
ConsoleKey.Packet
meant:The only OS that knows what
VK_PACKET
is, is Windows.In the fix (#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 (
ConsoleKeyMapping.DecodeVKPacketToKConsoleKeyInfo
etc...) a Scenario was developed to try to simulate things so this code could be better tested (VkeyPacketSimulator
).As far as I can tell, none of the core Terminal.Gui maintainers regularly test the VK_PACKET support in a real scenario (e.g. over RDP). No-one has yet to provide a reproducable real-world use case that anyone on the team can use.
The use-case we are discussing is completely tied to Windows. The only way a ConsoleDriver will ever get a key event with
ConsoleKey.Packet
is if the user is running their app on Windows and using that app over RDP (there may be other cases but nobody's articulated one precisely). The only ConsoleDrivers that will ever get a key event withConsoleKey.Packet
areWindowsDriver
andNetDriver
.The infrastructure code discussed above is inherently flawed. Specifically:
HashSet<ScanCodeMapping> _scanCodes
. It assumes it is possible to have a singular map of scancodes, virtual key codes (VK_), and shift modifiers to characters that works across all keyboard layouts. It, effectively, tries to duplicate what the Win32 methodMapVirtualKeyCode
does in a very simplistic way (that will never work).By extension to 2) above, the
VkeyPacketSimulator
is inherently flawed and doesn't do what it was intended to do (provide a way of testingVK_PACKET
handling inWindowsDriver
andNetDriver
).Not directly related to
VK_PACKET
support, but relevant is the fact thatWindowsDriver
andNetDriver
have always been flawed in how they handled keys likeOem3
. The only correct way to handle those keys is to useMapVirtualKeyCode
(this PR addresses this).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
VK_PACKET
key events are generated).b) Change
WindowsDriver
to useMapVirtualKeyCode
when key events withVK_PACKET
are received. Most of the code inConsoleKeyMapping
can be thrown away. #3078 addresses some of this.c) Built a better testing API into
ConsoleDriver
that lets us simulate VK_PACKET key events in unit tests such that bothWindowsDriver
andNetDriver
are better tested.d) Refactor the
VkeyPacketSimulator
to use c), so we can have a UI-based tester.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
VK_PACKET
support to Windows. I had created the concept of Windows Media Center Extenders (Bobsled) and we were in deep collaboration with the RDP team because I had the vision that Extenders would use RDP as their protocol. All UI could run on the Media Center PC an be remoted to the Bobsled device as GDI primitives via RDP. We needed two features RDP didn't have at the time:The RDP team had woken up to the fact that RDP didn't support Unicode and varying keyboard layouts well. Hence
VK_PACKET
was created (and the other Media Center specificVK_
keys such asVK_MEDIA_NEXT_TRACK
.I hope that there's a similar API to
MapVirtualKeyCode
(orGetKeyboardLayout
) on the Mac and Linux. There has to be. And it's possible the keyboard coding used maps well to a lot of WindowsVK_
defines. There may even be a key event that is similar toVK_PACKET
where all you get is the unicode char, which would be sweet. But that is a separate discussion.For this Issue to be addressed:
VK_PACKET
key events are generated).WindowsDriver
to useMapVirtualKeyCode
when key events withVK_PACKET
are received. Most of the code inConsoleKeyMapping
can be thrown away. Cleans up key handling in drivers (was "fixes VkeyPacketSimulator is broken") #3078 addresses some of this.ConsoleDriver
that lets us simulate VK_PACKET key events in unit tests such that bothWindowsDriver
andNetDriver
are better tested.VkeyPacketSimulator
to use c), so we can have a UI-based tester.For now, the
VkeyPacketSimulator
, much of the code inConsoleKeyMapping
, and most of the tests inConsoleKeyMappingTests.cs
are invalid/useless and should be ignored (or deleted)>The text was updated successfully, but these errors were encountered: