question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Key Up/Down/Press events don't work as expected. (at least on MacOS)

See original GitHub issue

Describe the bug KeyUp triggers the same time KeyDown is triggered, and KeyPress never get triggered at all.

To Reproduce Simply add event handlers to a view’s Key* events, or override the view’s OnKey* methods. The “Keys” scenario in the UICatalog behaves this way. Or here’s a working test I made:

public static class Program {
    private static Window SetupWindow() {
        List<string> keyEvents = new();
        ListView listView = new(keyEvents) {
            Height = Dim.Fill(),
            Width = Dim.Fill(),
        };

        Window window = new();
        window.Add(listView);

        window.KeyDown += args => {
            keyEvents.Add($"KeyDown: {args.KeyEvent}");
            listView.SelectedItem = listView.Source.Count - 1;
        };
        window.KeyUp += args => {
            keyEvents.Add($"KeyUp: {args.KeyEvent}");
            listView.SelectedItem = listView.Source.Count - 1;
        };
        window.KeyPress += args => {
            keyEvents.Add($"KeyPress: {args.KeyEvent}");
            listView.SelectedItem = listView.Source.Count - 1;
        };

        return window;
    }

    public static void Main(string[] args) {
        Application.Init();
        try {
            Window window = SetupWindow();
            Application.Run(window);
        } finally {
            Application.Shutdown();
        }
    }
}

Expected behavior KeyUp should run when the key is released rather than key is pressed down. KeyPress should run after both KeyDown and KeyUp events are run.

Desktop

  • OS: MacOS
  • Version 12.6.8 (Monterey)

Additional context I think the key events worked properly when I tested it on a Windows computer about a year ago… so I assume this has to do with the CursesDriver?

This has been a problem in Terminal.Gui for a long time, and I’ve not yet seen any bug report mentioning this… so I finally got around to writing it.

This hasn’t bothered me too much for “normal” applications, but I’m trying to make a “real-time” game with movement &c. based on when a key is down/up.

Issue Analytics

  • State:open
  • Created a month ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
BDispcommented, Aug 21, 2023

I already having this working with NetDriver and CursesDriver but I need a little more time to be sure that all is working well.

imagem

1reaction
Albator11commented, Aug 19, 2023

That would be awesome if you can get something working! Until then I think I’ll probably be happy enough with using SharpHook. 😃

I’m curious what your workaround might be though? And if you’d like any help with it, I wouldn’t mind trying to help. (although I wouldn’t call myself an expert by any means)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why doesn't the keyUp event work in Swift?
I've trying to use the keyUp event in swift so then I can detect when the user presses a key and when the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found