Key Events

Does a simpleOpenGLControl prevent key events from being fired? I have a this.keydown event that should fire whenever a key is pressed but it doesn't. Key presses do nothing. I've even added the simpleOpenGLControl.Keydown event and it still isn't fired. Any ideas why these event are being thrown. I have two buttons that work, so at least these event are working correctly. I am trying to create keydown events for the arrows to manipulate the simpleOpenGLControl.

Thanks for any help.

Unfortunately, you can't

Unfortunately, you can't process the arrow keys in a KeyPress or KeyDown event handler. Instead, you need to override the ProcessCmdKey() method in your form class. Here's a C# example:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;

if (((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN)) && simpleOpenGlControl1.Focused)
{
switch (keyData)
{
case Keys.Down:
world.IncrementElevation();
simpleOpenGlControl1.Refresh();
break;

case Keys.Up:
world.DecrementElevation();
simpleOpenGlControl1.Refresh();
break;

case Keys.Left:
world.DecrementAzimuth();
simpleOpenGlControl1.Refresh();
break;

case Keys.Right:
world.IncrementAzimuth();
simpleOpenGlControl1.Refresh();
break;

}
}
return base.ProcessCmdKey(ref msg, keyData);
}

Note: if you leave out the check for simpleOpenGlControl1.Focused, the arrow keys will always register no matter which control is focused. Also note that I'm still passing the keypress on to the base class even if I handle it here.

That works great! Thanks

That works great! Thanks for the help. You guys have done an excellent job with the Tao framework. I had been using csgl and was experiencing at lot of problems and lack of support.
Thanks Again.

Theme by La Boite a site | Powered by Drupal