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);
}
}
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With