如何在C#.Net中获取、屏蔽鼠标键盘消息?
来源:互联网 发布:家装颜色搭配技巧知乎 编辑:程序博客网 时间:2024/06/05 23:59
1static class StartupClass
2{
3 ///程序开始时候设置一个消息筛选MessageFilter,意思就是只要属于本程序的消息
4 ///都要经过处理以后再发给本程序 打个比方,程序起来以后再程序的text里输入一
5 ///个 9,但是这个9是系统先获得,然后系统通过消息的方式发给应用程序。这里的
6 ///MessageFilter的意思就是所有系统发给应用程序的消息都要处理一下。
7 [STAThread]
8 static void MyMain()//Main()
9 {
10 RButtonMessageFilter filter = new RButtonMessageFilter();
11 Application.AddMessageFilter(filter);
12
13 Application.EnableVisualStyles();
14 Application.SetCompatibleTextRenderingDefault(false);
15 Application.Run(new Form());
16 //移除
17 Application.RemoveMessageFilter(filter);
18 }//在程序开始的时候添加一个本程序的系统消息的监测。
19
20 //然后下面的类里处理所有的系统消息!
21 public class RButtonMessageFilter : IMessageFilter
22 {
23 public bool PreFilterMessage(ref Message m)
24 {
25 const int WM_RBUTTONDBLCLK = 0x206;
26 const int WM_RBUTTONDOWN = 0x204;
27 const int WM_RBUTTONUP = 0x205;
28
29 const int WM_KEYDOWN = 0x100;
30 const int WM_KEYUP = 0x101;
31
32 switch (m.Msg)
33 {
34 //过滤掉所有与右键有关的消息
35 case WM_RBUTTONDBLCLK:
36 case WM_RBUTTONDOWN:
37 case WM_RBUTTONUP:
38 {
39 return true;
40 }
41 case WM_KEYDOWN: //有键盘按下
43 {
45 int k = m.WParam.ToInt32();
46 if (k == 57)
47 {
48 //屏蔽按键9 9的 asicii吗是57
49 return true;
50 }
51 else
52 {
53 //按下的其他建不屏蔽
54 return false;
55 }
56 }
57 default:
58 {
59 return false;
60 }
61 }
62 }
63 }
64
65}
2{
3 ///程序开始时候设置一个消息筛选MessageFilter,意思就是只要属于本程序的消息
4 ///都要经过处理以后再发给本程序 打个比方,程序起来以后再程序的text里输入一
5 ///个 9,但是这个9是系统先获得,然后系统通过消息的方式发给应用程序。这里的
6 ///MessageFilter的意思就是所有系统发给应用程序的消息都要处理一下。
7 [STAThread]
8 static void MyMain()//Main()
9 {
10 RButtonMessageFilter filter = new RButtonMessageFilter();
11 Application.AddMessageFilter(filter);
12
13 Application.EnableVisualStyles();
14 Application.SetCompatibleTextRenderingDefault(false);
15 Application.Run(new Form());
16 //移除
17 Application.RemoveMessageFilter(filter);
18 }//在程序开始的时候添加一个本程序的系统消息的监测。
19
20 //然后下面的类里处理所有的系统消息!
21 public class RButtonMessageFilter : IMessageFilter
22 {
23 public bool PreFilterMessage(ref Message m)
24 {
25 const int WM_RBUTTONDBLCLK = 0x206;
26 const int WM_RBUTTONDOWN = 0x204;
27 const int WM_RBUTTONUP = 0x205;
28
29 const int WM_KEYDOWN = 0x100;
30 const int WM_KEYUP = 0x101;
31
32 switch (m.Msg)
33 {
34 //过滤掉所有与右键有关的消息
35 case WM_RBUTTONDBLCLK:
36 case WM_RBUTTONDOWN:
37 case WM_RBUTTONUP:
38 {
39 return true;
40 }
41 case WM_KEYDOWN: //有键盘按下
43 {
45 int k = m.WParam.ToInt32();
46 if (k == 57)
47 {
48 //屏蔽按键9 9的 asicii吗是57
49 return true;
50 }
51 else
52 {
53 //按下的其他建不屏蔽
54 return false;
55 }
56 }
57 default:
58 {
59 return false;
60 }
61 }
62 }
63 }
64
65}
- 如何在C#.Net中获取、屏蔽鼠标键盘消息?
- BlockInput屏蔽鼠标键盘消息
- 如何在QTP运行过程中屏蔽鼠标
- 如何在QTP运行过程中屏蔽鼠标
- 如何在QTP运行过程中屏蔽鼠标
- 【教程】如何在C#,VB.NET中提取消息内容
- js屏蔽鼠标键盘
- 如何获取鼠标在控件中位置
- 如何在C#中使用全局鼠标、键盘Hook
- 如何在C#中使用全局鼠标、键盘Hook
- 如何在C#中使用全局鼠标、键盘Hook
- 如何在C#中使用全局鼠标、键盘Hook
- 如何在C#中使用全局鼠标、键盘Hook
- 如何:在代码中模拟鼠标和键盘事件
- 如何在C#中使用全局鼠标、键盘Hook
- 如何在ArcMap中监听键盘鼠标事件
- 【教程】如何在C#,VB.NET中获取PDF书签
- 一、ASP.NET中屏蔽鼠标右键
- 存储层次结构、cache、编译
- USB转串口之minicom的设置
- 将已经存在的文件在aspx网页中输出的方法
- TCP加密通讯附记,实践中出现的问题。
- System.Data.OracleClient 需要 Oracle 客户端软件 8.1.7 或更高版本的解决方案【转】
- 如何在C#.Net中获取、屏蔽鼠标键盘消息?
- 自定义Ext/Coolite的GridPanel的交替行颜色
- SecureCRT连接Linux,终端显示中文乱码问题,全方面解决
- c语言谜题
- 显式事务控制的隐式提交
- java连接sqlserver
- Copy-On-Write机制,全局hook(二)
- Auriga降低展讯评级有点早
- 9月手记