Open sunfishcode opened 7 months ago
Admittedly, I don't know that much about Unicode. From a quick search it seems I meant scalar values. On that note, do all keys on keyboards have scalar values? Even special keys like "Page Up", the arrow keys and so on? Or do we need a special event for some keys? And should pressed modifiers alone emit an event?
Unicode doesn't cover all keyboard keys, so I assume we'll need a special event enum.
There exist GUI applications that expect events for pressed modifiers alone. We can make a choice about whether we want to support them though. It's probably worth looking at the major toolkits we'd expect people to use, so see if they expose modifier keypresses.
I decided for modifier keys, web browser support it, so it should be generally available. I also oriented myself on the browser key events in regards to a special key enum. I picked all keys I saw or heard about, I left out many obscure ones for now.
Currently, keyboard events are documented as producing code points:
https://github.com/tareksander/WASI-Windowing/blob/main/wit/event.wit#L28
Code points include surrogates, which can be awkward to work with; should you wait for the next event to see if it forms a surrogate pair, immediately replace it with a replacement character, or do something else?
Looking at the code that produces these events, the values are Rust
char
s, which are actually [Unicode Scalar Values], rather than code points:https://github.com/tareksander/WASI-Windowing/blob/e3b3491611211f98e4dd51832ece78750b9e35ef/example-runtime/src/main.rs#L227
Could events be defined in terms of Unicode Scalar Values instead of code points?