简体   繁体   English

windows phone 8.1 swype键盘事件捕获

[英]windows phone 8.1 swype keyboard event capture

Update [16-Jul-2014]: The question is technically incorrect. 更新[2014年7月16日]:问题在技术上是不正确的。 Read the answer to get more details. 阅读答案以获取更多详细信息。


I was trying to capture text before reaching to my text box. 我试图在到达我的文本框之前捕获文本。 and I discovered the following facts: 我发现了以下事实:

  • KeyDown , KeyUp event will tell you what virtualKey was pressed not the character !! KeyDownKeyUp事件会告诉你什么是virtualKey被按下而不是字符!!

  • CoreWindow.CharacterReceived will capture the character but this CoreWindow.CharacterReceived将捕获角色但是这个
    event is not specific to TextBox and it will tell you the character 事件不是TextBox特有的,它会告诉你角色
    after it reached to the textBox. 在它到达textBox之后。

Now my question is: 现在我的问题是:

Can any one tell me how can I capture the event of the Swype Keyboard on windows phone 8.1? 任何人都可以告诉我如何在Windows Phone 8.1上捕获Swype键盘的事件? 在此输入图像描述

Notice that : 请注意:

1- I tried to capture it in TextBox.Paste but it fails :( 1-我试图在TextBox.Paste中捕获它但它失败了:(

2- The event textBox.textChanged() is not what I am looking for bec that event fire after the keyboard is done and this event (textChanged) will fire after keyDown , keyUp , CharacterReceived regardless of how the text was input. 2-事件textBox.textChanged()不是我想要的,因为键盘完成后事件触发,并且此事件(textChanged)将在keyDownkeyUpCharacterReceived之后触发,无论文本是如何输入的。

OK! 好! I have been in this issue for days and extensively tested it to understand and came up with the following conclusions: 我已经在这个问题上待了好几天,并对它进行了广泛的测试以理解并提出了以下结论:

1- the input from keyboard is handled by the event of the page named ( CharacterRecieved ). 1-来自键盘的输入由名为( CharacterRecieved )的页面事件处理。 the event is fired and captured by the Page then sent to the TextBox and will result in the firing of TextChanged event. 该事件被页面触发并捕获,然后发送到TextBox ,并将导致触发TextChanged事件。

2- If you come to winRT and windows phone with the winForms mentality you will surely have the confusion i had, and will take some time to figure it out [unless you read this answer which will make it shorter]. 2-如果你带着winForms的心态来到winRT和windows手机,你肯定会有我的困惑,并且需要一些时间才能弄明白[除非你读到这个会让它缩短的答案]。

3- Don't expect [ as I falsely expected ] that the event of the character entered will fire in the TextBox. 3-不要指望[我错误地预期]输入的字符的事件将在TextBox中触发。 It will fire on the page (CoreWindow) then changes the text value of the textBox, so you have to catch the event on the page level, not on the control level. 它将在页面上触发(CoreWindow),然后更改textBox的文本值,因此您必须在页面级别而不是在控件级别上捕获事件。

4- Difference between entering one letter by keyboard and entering one word using swype keyboard: 4-通过键盘输入一个字母和使用swype键盘输入一个字之间的区别:

** **

  • in Case of One letter entered by the keyboard on the phone, the following sequence will mostl likely happen: 如果手机上的键盘输入了一个字母,则可能会发生以下顺序:

** **

suppose the textBox.Text = "99"; 假设textBox.Text = "99";

Now I will press the number 7: 现在我将按7号:

1- KeyDown event will fire: here you may capture the virtualKey but you won't be able to know the character, so pressing 'a' letter you can't know is it 'A' capital or 'a' small. 1- KeyDown事件将触发:在这里你可以捕获virtualKey但是你将无法知道这个字符,因此按下'a'字母,你不知道它是'A'大写还是'a'小。 still textBox.Text = "99"; 仍然是textBox.Text = "99";
2- CharacterRecieved Fire; 2- CharacterRecieved Fire; textBox.Text = "997";
3- KeyUp event fire; 3- KeyUp事件火灾; textBox.Text = "997";
4- textChanged fire.; 4- textChanged fire。; textBox.Text = "997";

  • while in case of swype-keyboard: 而在swype键盘的情况下:

suppose textBox.Text = "99"; 假设textBox.Text = "99"; and I want to enter the text "hello"; 我想输入文字“你好”;

swype will add white space before the word so it will be " hello" swype会在单词之前添加空格,因此它将是“hello”

and the event sequence is as follow: 事件顺序如下:

1- a loop for each character in the string " hello" will fire the event CharacterRecieved and the textBox.Text value will be textBox.Text= "99 " in the first iteration; 1-字符串“hello”中每个字符的循环将触发事件CharacterRecieved ,并且textBox.Text值将在第一次迭代中为textBox.Text= "99 " ; then from the second iteration the textBox.Text = "99 hello"; 然后从第二次迭代开始, textBox.Text = "99 hello"; in each iteration you can capture the key code [char] which is in this case (32, 110, 101, 108,108, 111). 在每次迭代中,您可以捕获key code [char] ,在这种情况下(32,110,101,108,108,111)。 notice that by now the textBox.Text value is changed however not yet shown on the screen !! 请注意,到目前为止, textBox.Text值已更改,但屏幕上尚未显示!!

2- The textChanged event will fire twice (weird !! i think one for the white space and the second for the word "hello"), Also, by now the textBox.Text = "99 hello" but still not yet shown on the screen till the end of the two iterations over the textChanged event. 2- textChanged事件将触发两次(奇怪!!我认为一个用于空格,第二个用于“hello”),另外,现在textBox.Text = "99 hello"但仍未显示在屏幕直到textChanged事件的两次迭代结束。

With this we come to notice the difference between swype and normal keyboard key events which is that in swype there is no keyDown keyUp events at all !! 有了这个,我们注意到swype和普通键盘键事件之间的区别,就是在swype中根本没有keyDown keyUp事件!

Now if you know the scenarios with each method of keyboard input ( swype/non-swype) you can plan your validation and application behaviour as you wish. 现在,如果您了解每种键盘输入方法(swype / non-swype)的方案,您可以根据需要规划验证和应用程序行为。 provided that you know it is totally different than the legacy windows system input. 只要您知道它与传统的Windows系统输入完全不同。

I hope this will help someone there and save him/her many hours of confusion and agony :) 我希望这会帮助那里的人,并拯救他/她多少小时的困惑和痛苦:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM