Med*_*000 3 c# service hotkeys
是否有可能让我的覆盖优先于系统范围,所以即使在运行Web浏览器,文字编辑器或绘图程序时(我的应用程序仍将在后台运行或显然是作为服务运行)
使用Visual C#2010
我如何覆盖我的代码的示例:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if((keyData == (Keys.Control | Keys.C))
{
//your implementation
return true;
}
else if((keyData == (Keys.Control | Keys.V))
{
//your implementation
return true;
}
else
{
return base.ProcessCmdKey(ref msg, keyData);
}
}
Run Code Online (Sandbox Code Playgroud)
use*_*830 12
你应该使用Global Hooks,Global Mouse和Keyboard Hook是一个很好的库,可以简化这个过程.这是一个基于您的问题的示例.
internal class KeyboardHook : IDisposable
{
private readonly KeyboardHookListener _hook = new KeyboardHookListener(new GlobalHooker());
public KeyboardHook()
{
_hook.KeyDown += hook_KeyDown;
_hook.Enabled = true;
}
private void hook_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.C && e.Control)
{
//your implementation
e.SuppressKeyPress = true; //other apps won't receive the key
}
else if (e.KeyCode == Keys.V && e.Control)
{
//your implementation
e.SuppressKeyPress = true; //other apps won't receive the key
}
}
public void Dispose()
{
_hook.Enabled = false;
_hook.Dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
使用范例:
internal static class Program
{
private static void Main()
{
using (new KeyboardHook())
Application.Run();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
312 次 |
| 最近记录: |