替换所有程序的 Windows 快捷方式

replace Windows short cuts for all programs

是否可以让我的覆盖在系统范围内优先,所以即使 运行 网络浏览器、文字编辑器或绘图程序(我的应用程序仍会 运行 在后台或显然是一项服务)

使用 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);
    }
}

你应该使用 Global Hooks,Global Mouse and 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();
    }
}

用法示例:

internal static class Program
{
    private static void Main()
    {
        using (new KeyboardHook())
            Application.Run();
    }
}