我想写一个这样的函数,
public System.Windows.Input.Key ResolveKey(char charToResolve)
{
// Code goes here, that resolves the charToResolve
// in to the Key enumerated value
// (For example with '.' as the character for Key.OemPeriod)
}
我知道我可以写一个巨大的 Switch-case 来匹配角色,但是还有其他方法吗?
问题是 Key 枚举的字符串可能与字符不匹配,因此 Enum.IsDefined 将不起作用
有任何想法吗?
更新:这是在Windows环境下
[DllImport("user32.dll")]
static extern short VkKeyScan(char ch);
static public Key ResolveKey(char charToResolve)
{
return KeyInterop.KeyFromVirtualKey(VkKeyScan(charToResolve));
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)