emoon / rust_minifb

Cross platfrom window and framebuffer crate for Rust
MIT License
1.03k stars 98 forks source link

Request feature to read typed keys #200

Closed john01dav closed 2 years ago

john01dav commented 4 years ago

The crate already supports determining if a particular key is down or not, but this is not sufficient to accept text input in a natural way. There are two specific goals that can't be fulfilled:

A proper event or mechanism to look at typed keys, as opposed to pressed keys, is needed to capture this complicated and OS-specific behavior. To provide this, I propose a new method on the minifb::Window struct, fn get_next_typed_char() -> Option<char> that, when called repeatedly, will give all characters that have been typed in the order that they were typed, then None once all types characters have been returned. This method could then be polled frequently (e.g. every frame) to get new information, that is simply passed along from the underlying OS-specific API. Note, however, that this is just one way to implement this, and that another method may be more convenient given the platform-specific underlying APIs (which are unknown to me).

john01dav commented 4 years ago

I found a solution, minifb::window::set_input_callback. I didn't originally find it because I expected to see something with the name "typed" in it, as other libraries have.

john01dav commented 2 years ago

I'm trying to use this feature (on library version 0.19.3 from crates.io), and it appears to not be working. I'm taking the u32 from the input callback and passing it to char::from_u32 (discarding any that don't have a mapping, although no discards are actually happening so that's not the problem) then appending to a string to allow the user to type, but when I use a compose key or even try to type a capitol letter, it does not work instead typing the key sequence (aside from alt of course) in the former case and the lowercase letter in the latter case. This is on Debian 11 under X11 and Gnome. I can provide a minimum, complete, verifiable example if that would be helpful