Key Up/Down/Press events don't work as expected. (at least on MacOS)
See original GitHub issueDescribe 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:
- Created a month ago
- Comments:9
Top GitHub Comments
I already having this working with
NetDriver
andCursesDriver
but I need a little more time to be sure that all is working well.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)