I got a question about KeyCode
and disabling special keys. I know this question was asked a few times, but I didn't find an answer I can use and which works so I came here to ask :)
I'm writing a program which blocks every key or key combinations (like Alt+F4
etc.). The application is not for me, it's for customers which only be able to navigate in this program. This all works fine, but I can't disable Left CTRL, Right CTRL or Alt
key. I got this code for try blocking these keys:
private void webBrowser1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.LControlKey)
{
MessageBox.Show("LCtrl", "Warnung", MessageBoxButtons.OK);
}
else if (e.KeyCode == Keys.RControlKey)
{
MessageBox.Show("RCtrl", "Warnung", MessageBoxButtons.OK);
}
else if (e.KeyCode == Keys.Alt)
{
MessageBox.Show("Alt", "Warnung", MessageBoxButtons.OK);
}
else if (e.KeyCode == Keys.Delete)
{
MessageBox.Show("Delete", "Warnung", MessageBoxButtons.OK);
}
}
I only use MessageBox.Show();
that I can see if it works. Delete
key works fine, but the other one not. Is it possible to do this without editing the registry
and for Win7? Does anyone know why or can give me a hint?
Cheers
EDIT: I block all other keys in this way: Blocking shortcut keys using c#