C# 怎么拦截WIN+D 和 显示桌面的消息 最好有具体代码
使用钩子的方式拦截,这里有个问题是我拦截不到WIN+D 这组快捷键?????有米谁知道怎么拦截????还有显示桌面的那个按钮执行怎么拦截????
public void Hook_Start()
{
// 安装键盘钩子
if (hHook == 0)
{
KeyBoardHookProcedure = new HookProc(KeyBoardHookProc);
Process[] process = System.Diagnostics.Process.GetProcesses();
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyBoardHookProcedure, GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);
//如果设置钩子失败.
if (hHook == 0)
{
Hook_Clear();
//throw new Exception("设置Hook失败!");
}
}
}
public int KeyBoardHookProc(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0)
{
KeyBoardHookStruct kbh = (KeyBoardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyBoardHookStruct));
}
}
------最佳解决方案-------------------- KeyPress != null))
{
KeyboardHookStruct keyboardHookStruct =
(KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));
// Is Control being held down?
bool control = ((GetKeyState(VK_LCONTROL) & 0x80) != 0)
------其他解决方案--------------------参考一下,可以用KeyDown或 KeyUp 来判断是否按下了Win+D
protected override int HookCallbackProcedure(int nCode, int wParam, IntPtr lParam)