none
自定义控件如何直接获取键盘(外置键盘和触摸键盘)的输入内容 RRS feed

全部回复

  • Hi, caozhongqian

    Input: Touch keyboard 这个sample是起作用的,请看这个sample的CustomControl1.xaml.cs里面的OnKeyDown函数:

     protected override void OnKeyDown(KeyRoutedEventArgs e)
            {   
               
                this.myTextBlock.Text = "A key was pressed @ " + DateTime.Now.ToString();
            }

    它并没有获取当前按下的键盘的内容,您可以在里面获取:

     protected override void OnKeyDown(KeyRoutedEventArgs e)
            {   
               
                this.myTextBlock.Text = e.Key+"A key was pressed @ " + DateTime.Now.ToString();
            }

    其中e.key就是获取当前的按键内容。

    您可以参考一下以下链接

    http://msdn.microsoft.com/en-us/library/windows/apps/hh868246.aspx

    祝您好运!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年10月24日 3:06
    版主
  • Hi,Keydown这个事件只会在用触摸键盘时执行,如果是外置键盘是没有效果的。但最大的问题不是在这里。如果我们要输入中文呢?比如现在我们要输入“中国”,按照使用win8自带输入发的习惯,我们这时只需要输入zg,输入发就会自动联想“中国 XX1 XX3...”,时候需要用户选择“中国”。  我的测试结果是用触摸键盘keydown这个事件会被触发两次,e.Key 为"Z"和"G",一点帮助都没有。我现在的想要的效果获取到用户选择的 “中国”,请问有没有方法? 

    2013年10月24日 7:33
  • Hi,

    sample的CustomControl1的xaml里面是定义了一个TextBlock 控件,如果您改为TextBox控件的话应该是会支持中文的输入的。

    您具体想实现什么呢?能否详细的描述一下!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年10月24日 9:04
    版主
  • HI,可能是我描述的不够清楚,所以让您误解了。我现在想要这么一个效果:自定义一个控件,当调用该控件的某个接口后键盘自动弹出(比如textbox.Focus()),并接收键盘输入(包括中英文),但是这些输入的字符内容是不显示在控件上的,而是直接发送到服务器上处理的?
    2013年10月24日 13:27