最近做的一个winform类型的项目中需要屏蔽系统热键,在网上搜索了一下,基本上都是调用api来进行hook操作,下面的代码就可以完成功能 using System; using System.IO; using System.Reflection; using System.Runtime.InteropServices; using System.Windows.Forms; namespace WAT.PMS { /// <summary> /// Description
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using Microsoft.Win32; using System.Runtime.InteropServices; using System.Diagnostics; namespace TrueLore.GGZYZXJG.Utility { /// <summary> /// 热键屏蔽 /// &l
#region 屏蔽Windows功能键(快捷键) public delegate int HookProc(int nCode, int wParam, IntPtr lParam); private static int hHook = 0; public const int WH_KEYBOARD_LL = 13; //LowLevel键盘截获,如果是WH_KEYBOARD=2,并不能对系统键盘截取,会在你截取之前获得键
新增类KeybordHookProc using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; namespace H
事件的起因是在做一个项目功能时,添加快捷键关闭声音,这个键最终选择了空格键,但是当按下空格键时,会把窗体中获取焦点的控件(比如按钮,文本框等)的单击事件触发,所以要屏蔽这个现象. 开始使用各种方法,在网上各种查,但是没有什么效果,最后在属性列表中找到一个:Keypreview,说明上表示是 窗体上的控件是否向主窗体注册键盘事件,默认是false,这时设置为true.这样还不行,还要在窗体的Keydown事件中进一步拦截,代码如下: if (e.KeyCode == Keys.Space) { e