C#控制台下测试鼠标按键消息
本文用C#测试鼠标按键的程序,注意在使用时要引入System.Windows.Forms命名空间
using System;
using System.Windows.Forms;
public class BlockLeftMouseButtonMessageFilter : IMessageFilter
{
const int WM_LBUTTONDOWN = 0x201;
const int WM_LBUTTONUP = 0x202;
public bool PreFilterMessage(ref Message m)
{
if(m.Msg == WM_LBUTTONDOWN)
{
Console.WriteLine("The left mouse button is down.");
return true;
}
if(m.Msg == WM_LBUTTONUP)
{
Console.WriteLine("The left mouse button is up.");
return true;
}
return false;
}
}
public class MainForm : Form
{
public static void Main()
{
MainForm MyForm = new MainForm();
BlockLeftMouseButtonMessageFilter MsgFilter = new BlockLeftMouseButtonMessageFilter();
Application.AddMessageFilter(MsgFilter);
Application.Run(MyForm);
}
public MainForm()
{
Text = "Message Filter Test";
}
}
本文源自:翔宇亭——IT乐园(http://www.biye5u.com),转载请保留此信息!
微信搜索“优雅的代码”关注本站的公众号,或直接使用微信扫描下面二维码关注本站公众号,以获取最新内容。
个人成长离不开各位的关注,你的关注就是我继续前行的动力。