如何将Form键转换为Wpf键? [英] How to convert Form keys to Wpf Keys?
问题描述
您好,我在wpf中使用了密钥挂钩机制( http://www.codeproject.com /KB/cs/globalhook.aspx )
但是在上面的lind中,它们使用表单键.但我想将其转换为Wpf.这里的问题是Forms键包含0到255和一些特殊的Enum成员,但在System.Windows.Input.Key中仅包含0-171 Enum me成员.如果我按171枚举键上方,它将通过异常.如何将表单密钥转换为Wpf密钥?或任何一个人都可以在以下链接中给我提供UserActivityHook的Wpf版本
="a href =" http://www.koders.com/csharp/fid477E4BD57EA637D92D19A65FEF3E160B4C7C139F.aspx?s=textbox> http: //www.koders.com/csharp/fid477E4BD57EA637D92D19A65FEF3E160B4C7C139F.aspx?s=textbox
hi
I'm Using Key Hooking Mechanism In wpf(http://www.codeproject.com/KB/cs/globalhook.aspx)
But in the above lind they use forms keys. But i want to convert it to Wpf. Here the problem is Forms keys contains 0 to 255 and some special Enum Members but in System.Windows.Input.Key contains only 0-171 Enum me members. If i Press above 171 Enum key it will through the exception. How can I Convert Form Keys to Wpf Keys? or any one one can give me Wpf Version Of the UserActivityHook
in the below link
http://www.koders.com/csharp/fid477E4BD57EA637D92D19A65FEF3E160B4C7C139F.aspx?s=textbox
推荐答案
不幸的是,这里没有直接转换,并且有两种类型的密钥.但是,解析它们并找出映射是否存在非常简单.如下所述,如果不存在具有相同名称的成员,则只需为该键放置特殊的大写代码,而不是尝试使用Parse()操作即可.
Sadly there's no direct cast there and there ARE two types of Key(s). However, it's pretty simple to parse them and figure out if a mapping exists. As noted below, if a member with the same identical name doesnt exist, it's simply a matter of placing special casing code for that key instead of trying the Parse() operation.
public 静态 System.Windows.Input.KeyWinformsToWPFKey(System.Windows.Forms.KeysinputKey) |
{ |
//如果存在需要的键,则不需要特殊映射,请在这里放置特殊情况逻辑... 尝试 |
.{ |
返回 (System.Windows.Input .Key)Enum.Parse( typeof (System.Windows.Input.Key),inputKey. ToString()); |
捕获 |
.{ |
//没有直接映射... 返回 System.Windows.Input.Key.None; |
public static System.Windows.Input.Key WinformsToWPFKey(System.Windows.Forms.Keys inputKey) |
{ |
// Put special case logic here if there's a key you need but doesn't map... |
try |
{ |
return (System.Windows.Input.Key)Enum.Parse(typeof(System.Windows.Input.Key), inputKey.ToString()); |
} |
catch |
{ |
// There wasn't a direct mapping... |
return System.Windows.Input.Key.None; |
} |
} |
这篇关于如何将Form键转换为Wpf键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!