Windows phone 8.1 capture swype keyboard events

Update [Jul 16, 2014]: The question is technically incorrect. Read the answer for more details.


I tried to capture the text before moving on to the text field. and I discovered the following facts:

  • KeyDown , KeyUp event will tell you that pressed virtualKey and not a character !!

  • CoreWindow.CharacterReceived will capture the character, but this event is not specific to the TextBox, and it will tell you the character after it reaches the text field.

Now my question is:

Can someone tell me how I can capture the Swype Keyboard event on Windows Phone 8.1? enter image description here

Note:

1- I tried to capture it in TextBox.Paste, but it failed: (

2. The textBox.textChanged() event is not what I'm looking for, because this event is after the keyboard is executed, and this event (textChanged) will fire after KeyDown , KeyUp , CharacterReceived regardless of how the text was entered.

+6
source share
1 answer

OK! I was on this issue for several days and tested it carefully to understand and came up with the following conclusions:

1- keyboard input is processed by a page event with the name ( CharacterRecieved ). the event is triggered and captured by the page, then sent to the TextBox and causes the TextChanged event to TextChanged .

2- If you come to winRT and a Windows phone with the winForms mentality, you are likely to get confused and take some time to figure it out [unless you read this answer, which will make it shorter].

3. Do not expect [as I falsely expected] that the event of the entered character will fire in the TextBox. It will light up on the page (CoreWindow), and then change the text value of the textBox, so you need to catch the event at the page level, not at the control level.

4 The difference between entering one letter from the keyboard and entering one word using the swype keyboard:

**

  • in the case of a single letter entered by the keyboard on the phone, the following sequence will be most likely:

**

suppose textBox.Text = "99";

Now I will press number 7:

1- KeyDown will happen: here you can capture virtualKey , but you won’t be able to recognize the character, so press β€œa”, which you cannot know, is β€œA” capital or 'small. another textBox.Text = "99";
2- CharacterRecieved Fire; textBox.Text = "997";
3- KeyUp fire events; textBox.Text = "997";
4- TextChanged fire; textBox.Text = "997";

  • , whereas in the case of a swype keyboard:

suppose textBox.Text = "99"; and I want to enter the text "hello";

swype will add a space before the word so that it is "hello"

and the sequence of events is as follows:

1- the cycle for each character in the string "hello" will trigger the CharacterRecieved event, and the value of textBox.Text will be textBox.Text= "99 " in the first iteration; then from the second iteration textBox.Text = "99 hello"; at each iteration, you can capture the key code [char] , which in this case (32, 110, 101, 108, 108, 111). note that so far the value of textBox.Text changed, but not yet shown on the screen!

2- The TextChanged event will fire twice (weird !! I think one is for white space, and the second is for the word "hello"). Also, by now textBox.Text = "99 hello" , but not yet shown at the end of two iterations for the textChanged event.

With this, we notice the difference between the swype and normal key key events that are in swype, there are no KeyDown KeyUp events !!

Now, if you know the scripts with each keyboard input method (swype / non-swype), you can plan your inspection and application behavior as you like. provided that you know that it is completely different from the legacy Windows system login.

I hope this helps someone out there and saves him / her many hours of confusion and agony :)

+4
source

Source: https://habr.com/ru/post/945981/


All Articles