this will work for sure. Be careful to handle KeyUp
event and not keyDown
.
private void mainForm_KeyUp(object sender, KeyEventArgs e)
{
if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
{
//insert here
}
}
For me, keyDown
didn't work, keyU
p worked instead for the same code.
I don't know why, but it seems because keyDown
event happens directly after you press any key, even if that was ctrl key, so if you pressed ctrl+Up you will press ctrl key before the UP key and thus the event will occur before you can press the other, also pressing the second key will triggers the event again.
While using KeyUp
will not trigger the event until you release the key, so you can press ctrl, and the press the second key, which will trigger one event.