internal class MyMessager : IMessageFilter
{
public bool PreFilterMessage(ref Message m)
{
//如果检测到有鼠标或则键盘的消息,则使计数为0.....
if (m.Msg == 0x0200 || m.Msg == 0x0201 || m.Msg == 0x0204 || m.Msg == 0x0207)
{
t = 0;
}
return false;
}
}
//或重写ProcessCmdKey的方法
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
int WM_KEYDOWN = 256;
int WM_SYSKEYDOWN = 260;
if (msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN)
{
switch (keyData)
{
case Keys.Escape:
this.Close();//esc关闭窗体
break;
}
}
return false;
}
原文:http://www.cnblogs.com/VictorBlog/p/5193110.html