windows手机8.1 swype键盘事件捕获 [英] windows phone 8.1 swype keyboard event capture

查看:168
本文介绍了windows手机8.1 swype键盘事件捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新[2014年7月16日]:问题在技术上不正确。阅读答案以获取更多详细信息。






我试图在到达文本框之前捕获文本。我发现了以下事实:




  • KeyDown KeyUp 事件将告诉你 virtualKey 是否被按下
    不是字符!!


  • CoreWindow.CharacterReceived 将捕获字符,但此

    事件不是特定于TextBox的,它会告诉你




现在我的问题是:



任何人都能告诉我如何在Windows Phone 8.1上捕获Swype键盘的事件?



注意:



1-我试图在TextBox.Paste中捕获它,但它失败:(



事件 textBox.textChanged()不是我正在寻找因为事件触发键盘完成后,此事件(textChanged)将触发后,,,keyUp CharacterReceived >

解决方案

OK!我一直在这个问题几天,广泛地测试它来理解和得出以下结论:



1-来自键盘的输入由名为( CharacterRecieved )的事件处理,事件触发并捕获页面然后发送到 TextBox ,并将导致 TextChanged 事件的触发。



2-如果你来winRT和windows手机与winform的心态,你一定会有我的困惑,并会花一些时间来计算出来[除非你读这个答案,这将使它较短]。



3-不要指望输入字符的事件会在TextBox中触发。它将在页面(CoreWindow)上触发,然后更改文本框的文本值,因此您必须在页面级别而不是在控件级别捕获事件。



4-通过键盘输入一个字母和使用swype键盘输入一个字符之间的区别:



**




  • 在通过手机键盘输入一个字母的情况下,以下序列中的
    最有可能发生:



**



假设 textBox.Text =99;



现在我将按数字7:



1- KeyDown 事件将触发:在这里你可以捕获 virtualKey 但是你不能知道字符,所以按知道是A首都还是A小。
still textBox.Text =99;

2- CharacterRecieved 火; textBox.Text =997;

3- KeyUp event fire; textBox.Text =997;

4- textChanged textBox.Text =997;




  • swype键盘:



suppose textBox.Text =99;
并且我想输入文本hello;



swype将在单词之前添加空格, p>

,事件序列如下:



1-字符串hello中每个字符的循环触发事件 CharacterRecieved textBox.Text 值为 textBox.Text =99 在第一次迭代中;然后从第二次迭代 textBox.Text =99 hello;
在每次迭代中你可以捕获键代码[char] ,在这种情况下(32,110,101,108,108,111)。请注意,现在 textBox.Text 值已更改,但尚未显示在屏幕上!



textChanged 事件将触发两次(奇怪的!我认为一个为空白,第二个为hello),现在, textBox.Text =99 hello,但仍未显示在屏幕上,直到textChanged事件的两次迭代结束。



有了这个,我们注意到swype和正常的键盘键事件之间的区别是在swype没有 keyDown keyUp 所有的事件!



现在,如果你知道每个键盘输入法(swype /非swype)的场景,你可以计划你的验证和应用程序行为如你所愿。只要你知道它是完全不同于传统的Windows系统输入。



我希望这将帮助某人在那里,并保存他/她多小时的困惑和痛苦:)


Update [16-Jul-2014]: The question is technically incorrect. 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 !!

  • CoreWindow.CharacterReceived will capture the character but this
    event is not specific to TextBox and it will tell you the character
    after it reached to the 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?

Notice that :

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

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.

解决方案

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). the event is fired and captured by the Page then sent to the TextBox and will result in the firing of TextChanged event.

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].

3- Don't expect [ as I falsely expected ] that the event of the character entered will fire in the 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.

4- Difference between entering one letter by keyboard and entering one word using swype keyboard:

**

  • in Case of One letter entered by the keyboard on the phone, the following sequence will mostl likely happen:

**

suppose the textBox.Text = "99";

Now I will press the number 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. still textBox.Text = "99";
2- CharacterRecieved Fire; textBox.Text = "997";
3- KeyUp event fire; textBox.Text = "997";
4- textChanged fire.; textBox.Text = "997";

  • while in case of swype-keyboard:

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

swype will add white space before the word so it will be " 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; then from the second iteration the 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). notice that by now the textBox.Text value is changed however not yet shown on the screen !!

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.

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 !!

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. provided that you know it is totally different than the legacy windows system input.

I hope this will help someone there and save him/her many hours of confusion and agony :)

这篇关于windows手机8.1 swype键盘事件捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆