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

Escape Key not invoking OnKeyDown on Window or Toplevel #3496

Closed
Bigsby opened this issue May 22, 2024 · 10 comments · Fixed by #3511
Closed

Escape Key not invoking OnKeyDown on Window or Toplevel #3496

Bigsby opened this issue May 22, 2024 · 10 comments · Fixed by #3511
Assignees
Labels
bug v1 For Issues & PRs targetting v1.x
Milestone

Comments

@Bigsby
Copy link

Bigsby commented May 22, 2024

Describe the bug
Escape key is not invoking OnKeyDown.

To Reproduce

using Terminal.Gui;

static class Program
{
    class MainWindow : Toplevel
    {
        Label labelDown;
        public MainWindow()
        {
            labelDown = new Label();
            labelDown.Text = "No key pressed yet!";
            Add(labelDown);
        }

        public override bool OnKeyDown(KeyEvent keyEvent)
        {
            labelDown.Text = $"Keydown {keyEvent}";
            return true;
        }
    }

    static void Main(string[] args)
    {
        Application.Init();
        try
        {
            Application.Run<MainWindow>();
        }
        finally
        {
            Application.Shutdown();
        }
    }
}

Expected behavior
When Escape key is pressed, OnKeyDown should be called with Key as Key.Esc.

Desktop:

  • OS: macOS 14.4.1
  • Terminal: Terminal and iTerm2
  • Version: Terminal.Gui v1.16.0, v2.0.0-pre.214
@tig tig added bug v1 For Issues & PRs targetting v1.x labels May 22, 2024
@tig tig added this to the V1.17 milestone May 26, 2024
@Bigsby
Copy link
Author

Bigsby commented May 27, 2024

@tig , Note that I updated the issue and added that I also tested this in version 2 and the issue remains. Maybe the tagging should be updated.

@tig
Copy link
Collaborator

tig commented May 27, 2024

Thanks.

This is likely due to the fact that CursesDriver think's it cute to support Esc...Key sequences to support the ancient *nix idiom.

I've never been a fan of that as it relies on arbitrary timing and is actually not needed.

We will fix this.

@dodexahedron
Copy link
Collaborator

This is likely due to the fact that CursesDriver think's it cute to support Esc...Key sequences to support the ancient *nix idiom.

😫

We will fix this.

🥳

@BDisp
Copy link
Collaborator

BDisp commented May 29, 2024

@tig , Note that I updated the issue and added that I also tested this in version 2 and the issue remains. Maybe the tagging should be updated.

In the version 2 it's working as expected and so nothing need to be fixed.

explorer_0n4i0k2S9M.mp4

To test copy and paste this code on a scenario.

    public override void Main ()
    {
        Application.Init ();
        try
        {
            Application.Run<MainWindow> ().Dispose ();
        }
        finally
        {
            Application.Shutdown ();
        }
    }

    class MainWindow : Toplevel
    {
        Label labelDown;
        public MainWindow ()
        {
            labelDown = new Label ();
            labelDown.Text = "No key pressed yet!";
            Add (labelDown);
        }

        public override bool OnKeyDown (Key keyEvent)
        {
            labelDown.Text = $"Keydown {keyEvent}";

            if (keyEvent == Key.Esc && MessageBox.Query ("Quit", "Do you really want to exit?", "Ok", "Cancel") == 0)
            {
                Application.RequestStop();
            }
            return true;
        }
    }

@Bigsby
Copy link
Author

Bigsby commented May 29, 2024

@BDisp , testing....

@Bigsby
Copy link
Author

Bigsby commented May 29, 2024

So. I tested against the latest versions in Nuget and every version from 2.0.0-pre.1221 onwards (inclusive) build but throw an exception exception on run. This:

Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'JetBrains.Annotations, Version=4242.42.42.42, Culture=neutral, PublicKeyToken=1010a0d8d6380325'. The system cannot find the file specified.

Anyhow, version 2.0.0-pre.949 works fine. Thank you!

@Bigsby
Copy link
Author

Bigsby commented May 29, 2024

I closed this for me but, maybe, you want to keep it open for v1 Maintenance. I'll do as you see fit. And I'll be happy to test it then.

@BDisp
Copy link
Collaborator

BDisp commented May 29, 2024

I closed this for me but, maybe, you want to keep it open for v1 Maintenance. I'll do as you see fit. And I'll be happy to test it then.

Open again, please. After the PR is merged it will be automatically closed. Thanks.

@Bigsby Bigsby reopened this May 29, 2024
@tig tig closed this as completed in #3511 May 29, 2024
tig added a commit that referenced this issue May 29, 2024
Fixes #3496. Escape Key not invoking OnKeyDown on Unix.
@Bigsby
Copy link
Author

Bigsby commented May 29, 2024

Tested in version 1.17.0-pre.62. All good! Great work!

@tig
Copy link
Collaborator

tig commented May 29, 2024

I'm working on getting v1.17.0 pushed to nuget right now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug v1 For Issues & PRs targetting v1.x
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants