Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard Event Disabled #18

Open
userolle opened this issue Feb 25, 2022 · 13 comments
Open

Keyboard Event Disabled #18

userolle opened this issue Feb 25, 2022 · 13 comments
Labels
4.0 bug Something isn't working needs verification
Milestone

Comments

@userolle
Copy link

userolle commented Feb 25, 2022

After using this GLControl in my form, The events like KeyDown KeyPress etc don't work anymore, not just for GLControl but for the form as well. Does anyone know why and how to fix this? (KeyPreview set to true already)

@userolle userolle reopened this Feb 25, 2022
@MarcioAB
Copy link

I have the same issue:

Steps to reproduce:
(1) Create a simple Form with OnKeyDown: key down works fine.
(2) Add nuget package OpenTK 4.7.1: key down works fine.
(3) Drop GLControl on the Form: key down does not work anymore.
(4) Add handler for GLControl (from GLControl events panel): key down does not work.

Workarround:

Use ProcessCmdKey and ProcessDialogKey in the mean time.

@NogginBops
Copy link
Member

@seanofw any ideas?

@seanofw
Copy link
Collaborator

seanofw commented Feb 28, 2022

I just built and tested the GLControl Input Test program, and it's working fine: I get KeyDown and KeyUp messages, both in native and WinForms mode.

@userolle and @MarcioAB, have you tried compiling the GLControl Input Test program to see if that's misbehaving for you? I can't reproduce the failures you're describing.

@MarcioAB
Copy link

MarcioAB commented Feb 28, 2022

Before follow this route (built GLControl Input Test) I just tested with a simple WinForms application with only nuget OpenTK.WinForms (4.0.0-pre6) and KeyDown still does not work when the control is dropped into de Form.
Having this simple WinForms application with only this package from OpenTK team seems to be a valid test environment.

@MarcioAB
Copy link

MarcioAB commented Mar 2, 2022

Same issue with "GLControl Input Test" program.
I'm using net6.0-windows TargetFramework and not netcoreapp3.1

@ttaneff
Copy link

ttaneff commented Mar 3, 2022

I also have run into this issue. After adding OpenTK.WinForms (4.0.0-pre.6) on NetCore 3.1 WinForms project and dropping the GLControl on the Form - onKeyDown() is not fired neither on the GLControl, nor on the host Form. However, interestingly enough when setting GLControl.Enabled = false, the OpenGL Context is still active AND the KeyDown event is being invoked on the Form...

P.S. KeyPreview = true for both test cases (MS VisualStudio Community 2019 v16.11.10)

@FrancisMartin-VB
Copy link

Globalement c'est un problème de Focus. Le formulaire et le glcontrol ne le reçoivent pas à l'ouverture.
Pour Il suffit de changer de fenêtre et de revenir sur le formulaire
ou
Ajouter dans le designer du formulaire
this.Shown += new System.EventHandler(this.Form1_Shown);
Ajouter dans le code du formulaire
private void Form1_Shown(object? sender, EventArgs e)
{
bool ret = Focus();
}

@NogginBops
Copy link
Member

@MarcioAB are you able to try doing what is suggested here?
Adding these lines to the appropriate places

this.Shown += new System.EventHandler(this.Form1_Shown);

private void Form1_Shown(object? sender, EventArgs e)
{
    bool ret = Focus();
}

@MarcioAB
Copy link

MarcioAB commented Mar 9, 2022

@NogginBops Yes, but it still does not work.

Program pass on Form1_Show(..) but still does not pass on OnKeyDown(..).
And continues to pass on ProcessCmdKey(..) what I am using as a workaround.

@ttaneff
Copy link

ttaneff commented Mar 12, 2022

After looking into the GLFW code of GLControl, I also considered that the issue is related to the focus of the NativeWindow which is created in the background. I noted that after starting the application the KeyPreviewEvent on the GLControl was called, but not passed to the Form. After minimizing and showing the form - the issue was resolved, so I forced GLControl.Focus() in the Form.Shown event. Doing what is propsed by @FrancisMartin-VB and @NogginBops is identical, and also works in my case.

@MarcioAB
Copy link

Over here forcing GLControl.Focus() does not solve the problem, including minimizing and showing the form.
But adding GLControl.Enabled = false is another workaround: GLControl keeps working and OnKeyDown(..) starts to work.

@robertk92
Copy link

I have the same issue but ProcessCmdKey and ProcessDialogKey don't work for me either.
Perhaps it's caused by something else but I worked around this by calling Focus() inside OnMouseDown handler of the GLControl which is good enough for my use-case.

@xPaw
Copy link

xPaw commented Jan 7, 2023

It seems that one of the problems is that GLControl isn't entirely focusable/selectable. I have buttons next to the GL control, and clicking a button breaks the keyboards stuff not registering key presses. Even clicking on the GL control still appears to retain focus the button I clicked before.

If I press the tab key to cycle to the GL control, it registers key presses again.

EDIT: After some testing, I was calling GLControl.Focus in VisibilityChanged event, and the native window gains focus and then immediately loses it (GLFW unsets itself?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.0 bug Something isn't working needs verification
Projects
None yet
Development

No branches or pull requests

8 participants