简体   繁体   English

Windows 8.1处理物理键盘输入

[英]Windows 8.1 Handling Physical Keyboard Input

I'm developing a Universal App in c# for Windows 8.1 我正在为Windows 8.1使用C#开发通用应用程序

I'm trying to catch keyboard input and from the on-line literature have been pointed to KeyDown event and KeyRoutedEventArgs and the Key property. 我正在尝试捕获键盘输入,并且从在线文献中可以找到KeyDown事件, KeyRoutedEventArgsKey属性。 This works fine for most key characters and returns VirtualKey enumerations such as VirtualKey.A. 这对于大多数键字符都可以正常工作,并返回VirtualKey枚举,例如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. 但是,当按下诸如.. ::>之类的字符时,如果将Key键与VirtualKey.Shift结合使用,则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). 碰巧的是,我使用的是意大利笔记本电脑键盘,当然,其布局与英国扩展键盘不同,因此在英国键盘上,分号(;)的键值为186(不移位或底部字符)在意大利语键盘上为188(作为Shift或顶级字符)。 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. 我过去曾经开发过WPF,Silverlight和.Net应用程序,不记得即使是结合游戏循环,也很难处理物理键盘输入,因为我只是使用Key或Keys枚举和OEM值。

How can I capture these punctuation characters when their respective key is pressed, irrespective of the keyboard layout? 无论键盘布局如何,如何在按下各自的键时捕获这些标点符号?

Answer provided by Hans Passant ( https://stackoverflow.com/users/17034/hans-passant ): 由Hans Passant提供的答案( https://stackoverflow.com/users/17034/hans-passant ):

Characters typed on a physical keyboard are exposed by this event: http://msdn.microsoft.com/en-us/library/windows.ui.core.corewindow.characterreceived.aspx 此事件公开了在物理键盘上键入的字符: http : //msdn.microsoft.com/zh-cn/library/windows.ui.core.corewindow.characterreceived.aspx

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

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