如何在WndProc中提取密钥数据 [英] How to extract keys data in WndProc

查看:74
本文介绍了如何在WndProc中提取密钥数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个重写NativeWindow类的类,以将WndProc函数与WinForms表单挂钩.我还想捕获按该窗体按下的键,但是我不知道如何从传递到WndProc函数的消息结构中提取键.

这是想法:

I have a class that overrides NativeWindow class to hook the WndProc function from a WinForms form. I also want to capture the key that pressed at that form, but I don''t know how to extract the keys from message structure that passed into WndProc function.

Here is the idea :

protected override void WndProc(ref Message m) {
    int WM_KEYDOWN = 0x0100;
    int WM_SYSKEYDOWN = 0x0104;
    if (m.Msg == WM_KEYDOWN || m.Msg == WM_SYSKEYDOWN) {
        // Here is the point when I want to extract the keys data.
    } else {
        base.WndProc(ref m);
    }
}



有什么想法可以提取类似于ProcessCmdKey函数的keyData参数的键数据吗?

在此先感谢.



Any idea how to extract the keys data that similar to keyData parameter of the ProcessCmdKey function ?

Thanks in advance.

推荐答案

这种方式可能更简单:

Maybe its easier this way :

protected override void WndProc(ref Message m) {
    int WM_KEYDOWN = 0x0100;
    int WM_SYSKEYDOWN = 0x0104;
    if (m.Msg == WM_SYSKEYDOWN || m.Msg == WM_KEYDOWN) {
        // Extracting keys data that similar to ProcessCmdKey's keyData parameter.
        Keys keyData;
        if ((Keys)((int)m.WParam) != Control.ModifierKeys) 
            keyData = (Keys)((int)m.WParam) | Control.ModifierKeys;
        else 
            keyData = (Keys)((int)m.WParam);
        // Do anything with keyData here ...
    } else {
        base.WndProc(ref m);
    }
}


这篇关于如何在WndProc中提取密钥数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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