Windows 8.1处理物理键盘输入 [英] Windows 8.1 Handling Physical Keyboard Input

查看:98
本文介绍了Windows 8.1处理物理键盘输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#开发适用于Windows 8.1的通用应用程序



我正在尝试捕获物理键盘输入并且从在线文献中指出到 KeyDown 事件和 KeyRoutedEventArgs 以及 Key 属性。这适用于大多数关键字符并返回 VirtualKey 枚举,例如 VirtualKey.A 。但是,当按下,。;:> 等字符时,Key属性设置为一个数字,如果与 VirtualKey.Shift一起按下该键,则此数字是相同的值这似乎表明它不代表键上的字符,但只代表物理键。



碰巧,我正在使用一个意大利笔记本电脑键盘当然与英国扩展键盘的布局不同,因此分号(;)的键值在英国键盘上为186(作为非移位或底部字符),在意大利键盘上为188(作为Shift或顶级角色)。因此,我很难捕捉到这些标点字符。



我过去开发过WPF,Silverlight和.Net应用程序并且不记得它是即使在组合游戏循环中也难以处理物理键盘输入,因为我只使用了Key或Keys枚举和OEM值。



如何捕获这些标点字符当按下各自的键时,无论键盘布局如何?

解决方案

物理键盘上输入的字符会被此事件暴露:

http://msdn.microsoft.com/en-us/library/windows.ui.core.corewindow.characterreceived.aspx

I'm developing a Universal App in c# for Windows 8.1

I'm trying to catch physical keyboard input and from the on-line literature have been pointed to KeyDown event and KeyRoutedEventArgs and the Key property. This works fine for most key characters and returns VirtualKey enumerations such as VirtualKey.A. However, when characters such as ,.;:> are pressed the Key property is set to a number and this number is the same value if the key is pressed in combination with VirtualKey.Shift which seems to indicate it is not representative of the characters on the key, but only represents the physical key.

As it happens, I'm using an Italian laptop keyboard which of course is laid out differently to a UK Extended keyboard so the Key value for a semicolon (;) is 186 on a UK keyboard (as an un-Shifted or bottom character) and is 188 on an Italian keyboard (as a Shift or top character). I'm therefore stumped as far a capturing these punctuation characters.

I have developed WPF, Silverlight and .Net app in the past and don't remember it being as difficult to handle physical keyboard input even in combination a game loop, as I just used the Key or Keys enumeration and an OEM value.

How can I capture these punctuation characters when their respective key is pressed, irrespective of the keyboard layout?

解决方案

Characters typed on a physical keyboard are exposed by this event:
http://msdn.microsoft.com/en-us/library/windows.ui.core.corewindow.characterreceived.aspx


这篇关于Windows 8.1处理物理键盘输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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