SFML community forums

Help => General => Topic started by: MrAlce on August 14, 2022, 05:08:54 pm

Title: How do i read keyboard keys for every kind of keyboard?
Post by: MrAlce on August 14, 2022, 05:08:54 pm
I have been using SFML for a while, and for games its great. But now im working in a text editor and there is a small issue: when i try to read a key like semicolon or tilde, turn out to be other keys on my keyboard.

I guess this happens because my keyboard doesn't have the same key distribution as the english ones (im from Spain and here we have the ñ and ç key).

I fixed the problem by changing the sf::Keyboard::Key code for each key on my keyboard, pressing each key to find out. Now my program can be used by English and Spanish keyboards, but I would like that other types of keyboards could also be adapted (for example Japanese, Arabic...).

Is there any way to know what value sf::Keyboard::Key really has in these cases?
Title: Re: How do i read keyboard keys for every kind of keyboard?
Post by: G. on August 15, 2022, 02:32:12 am
Text editor? Probably want to use the sf::TextEntered (https://www.sfml-dev.org/tutorials/2.5/window-events.php#the-textentered-event) event instead, it is made to read text input.
Title: Re: How do i read keyboard keys for every kind of keyboard?
Post by: MrAlce on August 15, 2022, 05:24:40 pm
Thank you, sf::TextEntered is able to read correctly all of my keyboard's keys :), but it will work for every kind of keyboard?
Title: Re: How do i read keyboard keys for every kind of keyboard?
Post by: eXpl0it3r on August 15, 2022, 05:38:14 pm
If you're looking for text input, then TextEntered is the way to go, if you're looking for key events (pressed/released), then there's currently no easily solution.
The Scancode feature is being finalized, which will provide keyboard layout independent key codes.
Until then, I can recommend using something like Thor's ActionMap (https://bromeon.ch/libraries/thor/tutorials/v2.0/actions.html), going with the most command layout for your target audience, while allowing them to rebind the keys.