可能重复:
如何在 c# 中禁用 windows 键?
如何在我的 c# windows 应用程序中禁用 windows 键?
看看这个库:
http://globalmousekeyhook.codeplex.com/
作为使用此库和以下代码段的示例,您可以禁用 WinKey + R 组合。有两个步骤 1. 检测组合 2. 通过设置禁用进一步处理e.Handled = true
。希望能帮助到你。
private KeyboardHookListener m_KeyboardHookManager;
private bool m_LeftWinKeyIsDown;
private bool m_RightWinKeyIsDown;
private void TestForm_Load(object sender, EventArgs e)
{
m_KeyboardHookManager = new KeyboardHookListener(new GlobalHooker());
m_KeyboardHookManager.KeyDown += HookManager_KeyDown;
m_KeyboardHookManager.KeyUp += HookManager_KeyUp;
m_KeyboardHookManager.Enabled = true;
}
private void HookManager_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode ==Keys.LWin) m_LeftWinKeyIsDown = true;
if (e.KeyCode ==Keys.RWin) m_RightWinKeyIsDown = true;
if ((m_LeftWinKeyIsDown || m_RightWinKeyIsDown) && e.KeyCode == Keys.R) e.Handled = true;
}
private void HookManager_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.LWin) m_LeftWinKeyIsDown = false;
if (e.KeyCode == Keys.RWin) m_RightWinKeyIsDown = false;
}