no2345
Topic Author
Posts: 4
Joined: 31 Mar 2020, 01:37

Sending key down events to TextBox

04 Apr 2020, 01:11

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.

Tags:
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Sending key down events to TextBox

04 Apr 2020, 14:34

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.
 
no2345
Topic Author
Posts: 4
Joined: 31 Mar 2020, 01:37

Re: Sending key down events to TextBox

04 Apr 2020, 18:41

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
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Sending key down events to TextBox

04 Apr 2020, 21:30

The view provide several functions to inject events: KeyDown, KeyUp, Char, MouseMove...
 
no2345
Topic Author
Posts: 4
Joined: 31 Mar 2020, 01:37

Re: Sending key down events to TextBox

04 Apr 2020, 21:53

I have tried sending events directly to the view but still no luck. It is receiving the events but the text is not updating.
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Sending key down events to TextBox

04 Apr 2020, 22:06

Make sure that the TextBox has focus and also send the events in this order: KeyDow, Char, KeyUp for each keypress.
 
no2345
Topic Author
Posts: 4
Joined: 31 Mar 2020, 01:37

Re: Sending key down events to TextBox

05 Apr 2020, 18:47

Sending all 3 events ended up doing it. I miss read the documentation the first time. Thanks for your help!
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Sending key down events to TextBox

05 Apr 2020, 19:04

Great!

Who is online

Users browsing this forum: Google [Bot] and 0 guests