Gui.cs: Enter special non-standard characters in TextField

Created on 6 May 2018  ·  22Comments  ·  Source: migueldeicaza/gui.cs

Is it possible somehow processing non-standard characters in TextField like '=', '\' or numbers? Thanks.

Most helpful comment

Thanks for the bug report folks, and thanks for tracking this down @nickvdyck!

The fix should be in git now.

All 22 comments

Just ran into this as well. Is there only support for text without numbers?

Team, I do not understand this, what platform is this, and what is the problem?

Perhaps you are using the Keypad, instead of the main keyboard?

It is about non-standard characters, e.g. how to put the next string to TextField: Holly-Molly_23.

This only happens on windows. For windows it uses a different key map function eg MapKey https://github.com/migueldeicaza/gui.cs/blob/master/Terminal.Gui/Driver.cs#L1056 . This does some filtering to only include characters between A-z. Because the mapping into a ConsoleKey only allows you to map to standard keys. The unix code path uses a different map function eg MapCursesKey https://github.com/migueldeicaza/gui.cs/blob/master/Terminal.Gui/Driver.cs#L545.

Currently tested on Microsoft Windows [Version 10.0.17134.1] with dotnet core 2.1.0.rc1

I can try to make a put together a patch if given some pointers. 😁

Thanks for the bug report folks, and thanks for tracking this down @nickvdyck!

The fix should be in git now.

@migueldeicaza Thank you! It now works for the en-US keyboard. With the de-CH (Swiss German) keyboard layout we also have keys like AltGr, which we use for thinkgs like @,# or \ . These don't work yet. Is this easy to implement or do you have to create keymaps for all keyboard layouts?

Sorry, I didn't get it. Is there any plan to add supporting of this Windows symbols? Or is there any plan to add it? Sorry for bothering.

I am using
image

@YauhenPyl For me it already works with 0.8.0

@luetm: could you print out the results of using Console.ReadKey for any characters that are failing for you?

Agreed with @luetm , it is actually working with 0.8:
image
Thank you.

Excellent - will close

Sorry for the late reply.

I still cannot use the @ in 0.8.0. I think this might be a windows bug in relation to the de-CH layout. To make an @ with this layout I need to use this combo: https://i.imgur.com/k5WAs2y.png

Pressing this combination gives me the '2' character in a field. Any steps I can do to help debugging?

Yes, can you use Visual Studio and debug what happens in read key event processing?

I created a PR (https://github.com/migueldeicaza/gui.cs/pull/90). This seems to fix it, but like I mention there i found something else. Also occurs without my changes though. Maybe we'll open a new issue for that later.

Can you please try the latest version, I have now a proper fix for the TextField.

With 0.10.0 I get an exception every time I delete a character with backspace. AltGr + 2 still gives me a 2. But if the branch you use for nuget is master, the AltGr is not handeled. (https://github.com/migueldeicaza/gui.cs/blob/2af83a14cc6e543cd2cb08f2e5f59c8dc63ab092/Terminal.Gui/Drivers/WindowsDriver.cs#L663). The way I tried it here https://github.com/migueldeicaza/gui.cs/pull/90/commits/5bfeaa3bf29cde0a6e10c6546e601da33133bbc7 seems to work, since AltGr apparently is equivalent to Alt + Control.

I'll investigate the backspace problem a bit further.

System.InvalidOperationException: 'Operation is not valid due to the current state of the object.'
at Terminal.Gui.TextField.RuneIndexToByteIndex(Int32 index)
at Terminal.Gui.TextField.ProcessKey(KeyEvent kb)
at Terminal.Gui.View.ProcessKey(KeyEvent keyEvent)
at Terminal.Gui.View.ProcessKey(KeyEvent keyEvent)
at Terminal.Gui.Toplevel.ProcessKey(KeyEvent keyEvent)
at Terminal.Gui.View.ProcessKey(KeyEvent keyEvent)
at Terminal.Gui.Toplevel.ProcessKey(KeyEvent keyEvent)
at Terminal.Gui.Application.ProcessKeyEvent(KeyEvent ke)
at Terminal.Gui.WindowsDriver.Mono.Terminal.IMainLoopDriver.MainIteration()
at Mono.Terminal.MainLoop.MainIteration()
at Terminal.Gui.Application.RunLoop(RunState state, Boolean wait)
at Terminal.Gui.Application.Run(Toplevel view)
at Terminal.Gui.Application.Run()
at MailWilly.Program.Main(String[] args) in C:\Dev\VirtualWilly\VirtualWilly\Program.cs:line 62

This is on Windows I imagine?

Could you try dumping the values that come out of reading the text when you do AltGr+2? I do not know how to achieve the same on my US keyboard.

AltGr is like Ctrl + Alt. Full value of keyInfo:

Key D2 System.ConsoleKey
KeyChar 64 '@' char
Modifiers Alt | Control System.ConsoleModifiers

That was the point of https://github.com/migueldeicaza/gui.cs/pull/90 :)

The if (keyInfo.Modifiers == (ConsoleModifiers.Alt | ConsoleModifiers.Control)) return (Key)((uint)keyInfo.KeyChar); makes it work.

EDIT: Windows 10, .NET 4.6.1

Thanks for the information, one last thing, as I do not have a german keyboard, what does AltGr + 2 produce on a text editor, or say notepad?

The '@' symbol.

Thanks for helping me track this down, this should be fixed now.

Fixed. Closing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rueckertch58521 picture rueckertch58521  ·  16Comments

qdwang picture qdwang  ·  14Comments

psantosl picture psantosl  ·  21Comments

tig picture tig  ·  21Comments

timothyparez picture timothyparez  ·  26Comments