C#窗口拦截键盘事件
有时候需要拦截键盘的事件使程序按照设计者的要求执行。
protected override void WndProc(ref Message m)
{
const int WM_HOTKEY = 0x0312; // 热键消息
if (m.Msg == WM_HOTKEY)
{
//最大最小化热键
}
// 鼠标左键右键中间滑轮事件时,屏保计时器清零 [9/15/2010 huzhonghua]
const int WM_LBUTTONDOWN = 0x0201;
const int WM_RBUTTONDOWN = 0x0204;
const int WM_MOUSEDOWN = 0x0210;
const int WM_MOUSEWHEEL = 0x020A;
if (m.Msg == WM_MOUSEDOWN || m.Msg == WM_LBUTTONDOWN || m.Msg == WM_RBUTTONDOWN || m.Msg == WM_MOUSEWHEEL)
{
//所有键盘事件
}
base.WndProc(ref m);
}