not-fl3 / macroquad

Cross-platform game engine in Rust.
Apache License 2.0
3.38k stars 326 forks source link

Feature request: A way to get input that doesn't depend on layout #260

Open martin-t opened 3 years ago

martin-t commented 3 years ago

The current set of input related functions all respect the current layout. This means

As a result, it's impossible to have sane default keybindins that will work for all players. I think Macroquad should expose an alternative way to enumarate keys which would only depend on their physical location, not the player's layout.

not-fl3 commented 3 years ago

macroquad's keycodes do not depend on layout (just tried switching between languages, KeyCode::W still works)

martin-t commented 3 years ago

Which layouts are you trying? When i switch between English and Czech, then pressing the same physical key produces either Y or Z. Also, i am using get_last_key_pressed() and the number row which contains +ěščřžýáíé returns None, same for they keys around Enter, which contain "ú)ů§¨".

not-fl3 commented 3 years ago

I tried this: setxkbmap -model pc104 -layout cz,us -variant ,dvorak -option grp:alt_shift_toggle

than all the keys went crazy, but KeyCode::W still worked

Also just from the code - we do receive KeyCode's not characters, so I am not really sure how to reproduce/fix this

martin-t commented 3 years ago

Hmm, this is weird. When i run your command and then toggle layouts using alt+shift, nothing changes in MQ - each physical key returns the same KeyCode. However, when i toggle layouts by running the setxkbmap command, the keycodes change.

E.g. if you run setxkbmap -model pc104 -layout us, then the number row gives stuff like Some(KeyCode::Key1), if you then run setxkbmap -model pc104 -layout cz, it returns None. The same thing happens when toggling layouts using KDE.