这就是我的工作,我还添加了Alt F4以防止应用程序关闭 .
private static bool lastWasCtrlKey = false;
private static IntPtr captureKey(int nCode, IntPtr wp, IntPtr lp)
{
if (nCode >= 0)
{
KBDLLHOOKSTRUCT objKeyInfo = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lp, typeof(KBDLLHOOKSTRUCT));
// Disabling Windows keys
switch (objKeyInfo.key)
{
case Keys.RWin:
case Keys.LWin:
case Keys.Tab when HasAltModifier(objKeyInfo.flags):
case Keys.Escape when HasAltModifier(objKeyInfo.flags):
case Keys.Delete when HasAltModifier(objKeyInfo.flags):
case Keys.F4 when HasAltModifier(objKeyInfo.flags):
case Keys.Escape when lastWasCtrlKey:
lastWasCtrlKey = false;
return (IntPtr)1;
case Keys.LControlKey:
case Keys.RControlKey:
lastWasCtrlKey = true;
break;
case Keys.LShiftKey:
case Keys.RShiftKey:
// Do nothing as the Ctrl key could have been before this
break;
default:
lastWasCtrlKey = false;
break;
}
}
return CallNextHookEx(ptrHook, nCode, wp, lp);
}