如何将VirtualKey转换为WinRT的非美国键盘布局一个char? [英] How to convert a VirtualKey to a char for non-US keyboard layouts in WinRT?

查看:169
本文介绍了如何将VirtualKey转换为WinRT的非美国键盘布局一个char?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在标准的.NET存在着的toascii将/ ToUnicode和MapVirtualKey功能,利用该功能保健,但它似乎相当职能或库尚未被纳入地铁/ WinRT的。如果确实没有等价的函数或库在Metro / WinRT中暴露那么这将创建一个自定义文本输入框很难给市场带来非美国家。
具体的例子:在我的自定义控件,如果法国键盘用户按下电子,U,E或A键,它们不能被翻译成正确的字符。例如,E用来VirtualKey.Number7扫描码,而据我可以告诉是没有办法知道的键盘布局或没有简单的方法来翻译基于当前的键盘布局的扫描码。
没有人有这个情况吗?

In standard .NET there existed the ToAscii/ToUnicode and MapVirtualKey functions to take care of this functionality, though it seems an equivalent function or library has not been brought into Metro/WinRT. If there is actually no equivalent function or library exposed in Metro/WinRT then that would make a custom text input box VERY difficult to bring to market in non-US countries. Specific example: in my custom control, if a french keyboard user presses the è,ù,é, or à keys, they are unable to be translated to the correct character. For example, è uses the scan code for VirtualKey.Number7, and as far as I can tell there is no way to know the keyboard layout or no easy way to translate that scancode based on the current keyboard layout. Does anyone have some information about this?

推荐答案

我想这取决于你在找什么。如果你正在寻找一个简单的英文字母或数字,你可以简单地做到这一点:

I suppose it depends on what you are looking for. If you are looking for a simple English letter or number, you can simply do this:

private static char? ToChar(VirtualKey key, bool shift)
{
    // convert virtual key to char
    if (32 == (int)key)
        return ' ';

    VirtualKey search;

    // look for simple letter
    foreach (var letter in "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    {
        if (Enum.TryParse<VirtualKey>(letter.ToString(), out search) && search.Equals(key))
            return (shift) ? letter : letter.ToString().ToLower()[0];
    }

    // look for simple number
    foreach (var number in "1234567890")
    {
        if (Enum.TryParse<VirtualKey>("Number" + number.ToString(), out search) && search.Equals(key))
            return number;
    }

    // not found
    return null;
}



祝你好运!

Best of luck!

这篇关于如何将VirtualKey转换为WinRT的非美国键盘布局一个char?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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