Page 1 of 1

Sending key down events to TextBox

Posted: 04 Apr 2020, 01:11
by no2345
I am trying to send KeyDown/KeyUp Events to a TextBox when a User clicks a button from a separate NoesisView, something close to a virtual keyboard.
I have been using Unity and C#
I did a bunch of tests on the same NoesisView to see if that was the issue, but still no luck.

I have tried creating a new KeyEventArg and raising that event on the TextBox instance.
((Button)FindName("TestButton")).Click += (sender, eventArgs) =>
{
    var textBox = ((TextBox)FindName("TestInput"));
    var kea = new KeyEventArgs(textBox, Noesis.Keyboard.KeyDownEvent, Key.A, KeyStates.Down | KeyStates.Toggled);
    textBox.Focus();
    textBox.RaiseEvent(kea);
};
I have tried calling KeyDown on the TextBox View
var textBox = ((TextBox)FindName("TestInput"));
textBox.Focus();
textBox.View.KeyDown(Key.A);
The following works but I need to be able to send control keys to the TextBox
((Button)FindName("TestButton")).Click += (sender, eventArgs) =>
{
    var textBox = ((TextBox)FindName("TestInput"));
    textBox.Focus();
    textBox.View.Char('c');
};
Is there a different way I should be doing this? or am I missing something.
I know I can use the Win32 API to send key events that way but I would like to use the framework if I can.

Re: Sending key down events to TextBox

Posted: 04 Apr 2020, 14:34
by jsantos
I am trying to send KeyDown/KeyUp Events to a TextBox when a User clicks a button from a separate NoesisView, something close to a virtual keyboard.
Have you tried sending the events directly to the view? That's the way we are implementing Virtual Keyboards and IME in a few platforms.

Re: Sending key down events to TextBox

Posted: 04 Apr 2020, 18:41
by no2345
How would I go about doing that? The View doesn't contain a RaiseEvent method. Is there another way I can send events directly to the View?
If I bind to the KeyDown event on the TextBox it does receive the event
((TextBox)FindName("TestInput")).KeyDown += (sender, keyArgs) =>
{
    Debug.Log(keyArgs.Key);
};
But the actual text inside of the TextBox doesn't update

Re: Sending key down events to TextBox

Posted: 04 Apr 2020, 21:30
by jsantos
The view provide several functions to inject events: KeyDown, KeyUp, Char, MouseMove...

Re: Sending key down events to TextBox

Posted: 04 Apr 2020, 21:53
by no2345
I have tried sending events directly to the view but still no luck. It is receiving the events but the text is not updating.

Re: Sending key down events to TextBox

Posted: 04 Apr 2020, 22:06
by jsantos
Make sure that the TextBox has focus and also send the events in this order: KeyDow, Char, KeyUp for each keypress.

Re: Sending key down events to TextBox

Posted: 05 Apr 2020, 18:47
by no2345
Sending all 3 events ended up doing it. I miss read the documentation the first time. Thanks for your help!

Re: Sending key down events to TextBox

Posted: 05 Apr 2020, 19:04
by jsantos
Great!