Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replace Windows short cuts for all programs

is it possible to have my overrides take precedence system wide, so even when running a web browser, word editor, or paint program (my app would still be running in the Background or as a service obviously)

using Visual C# 2010

Sample of how I'm overriding in my code:

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);
    }
}
like image 731
Medic3000 Avatar asked Dec 29 '25 05:12

Medic3000


1 Answers

You should use Global Hooks, Global Mouse and Keyboard Hook is an excellent library which simplifies the process. here is an example based on your question.

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();
    }
}

Usage sample:

internal static class Program
{
    private static void Main()
    {
        using (new KeyboardHook())
            Application.Run();
    }
}
like image 118
user3473830 Avatar answered Dec 31 '25 19:12

user3473830