Georg Jansen posted on February 02, 2006 09:02
In a windows form I needed to detect if the tab key was pressed, but Tab keys are “eaten” by windows, creating a KeyPress event on the textbox won’t do it.
But I fond the ProcessCmdKey you can put on the form, the code below did it:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(textBox1.Focused == true) // do the textbox have focus?
{
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;
if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
if(keyData == Keys.Tab)
{
MessageBox.Show("tab key pressed inside textbox1");
return true; // I have processed the key
}
}
}
return false; // Key not prcessed by me
}