puklaus's picture

WinForms and keyboard

Hi. Im using GLControl in winforms and not sure how I am using keyboard. Now I have event-based system
(and dont like it, must say), can I use something like with GameWindow, ie

if(Keyboard[Key.Esc]) { break; } ?

Some my code, is this even right?

private void glControl1_KeyDown(object sender, KeyEventArgs e)
{
            switch (e.KeyData)
            {
                case Keys.A:    keyAction[0] = true;    break;
// more cases..
            }
}
 
private void glControl1_KeyUp(object sender, KeyEventArgs e)
{
            switch (e.KeyData)
            {
                case Keys.A:    keyAction[0] = false;    break;
// more cases..
            }
}
 
// called from Paint or some idle loop
void Render()
{
    if(keyAction[0]) x--;
}

Much code to do so simple thing... and if I hold shift when pressing A, and then release A, it wont call KeyUp.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
puklaus's picture

Well I found solution
http://stackoverflow.com/questions/1100285/how-to-detect-the-currently-p...

and KeyMessageFilter example works fine.