casanovaC4's picture

GLControl Disables Arrow Keys From Raising Form's KeyDown Event . . . . .

Project:The Open Toolkit library
Category:bug report


I tried to use GLControl's own KeyDown Events to use in my application but Arrow Keys(up, down, left, right) do not raise it's events.
But then i tried to use Form's KeyDown Events and Arrow Keys were not working here either but the rest of the keys do.

Then i used Windows.Panel and checked to make sure if there was nothing with the Form but here both Panel's and Form's KeyDown Events were being raised by Arrow Keys.

I have supplied code in C# which explains the problem a lot clearly.
Just try commenting and uncommenting and see it for yourself.

OpenTK version used :
Problem persists in : as well.

OpenTK Bug Report.zip1.79 KB


Comment viewing options

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


This is actually because the Control consumes those keys by default.

Derive from the GLControl and add the following method override:

        protected override bool IsInputKey(Keys keyData)
            //force all keys to be passed to the regular key events
            return true;

This will mean that certain child controls will lose tab navigation, text entry, etc. if you consume those key events so you can selectively enable the ones that are required.

the Fiddler's picture


Thanks for the pointer. casanovaC4, can you please test whether this solves the issue for you?

casanovaC4's picture


Yes the above solution did solve my problem.
But I think GLControl should not alter Form's own KeyDown Events.

Anyhow It's working now.

Thank you very much.

Kind Regards.

the Fiddler's picture


Status:open» closed

Thanks for confirming.

This is a general issue that stems from the Windows.Forms design, rather than something specific to GLControl-specific. GLControl itself does not interact with the keyboard/mouse in any way: these events are provided by the base System.Windows.Forms.UserControl class (i.e. we cannot alter its implementation).

objarni's picture


Is there alternatives to inheriting from GLControl to make arrow keys work?

the Fiddler's picture


Yes, handle the PreviewKeyDown event.