Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How do i read keyboard keys for every kind of keyboard?  (Read 381 times)

0 Members and 1 Guest are viewing this topic.

Vestelion

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
How do i read keyboard keys for every kind of keyboard?
« 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?

G.

  • Hero Member
  • *****
  • Posts: 1566
    • View Profile
Re: How do i read keyboard keys for every kind of keyboard?
« Reply #1 on: August 15, 2022, 02:32:12 am »
Text editor? Probably want to use the sf::TextEntered event instead, it is made to read text input.

Vestelion

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: How do i read keyboard keys for every kind of keyboard?
« Reply #2 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10332
    • View Profile
    • development blog
    • Email
Re: How do i read keyboard keys for every kind of keyboard?
« Reply #3 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, going with the most command layout for your target audience, while allowing them to rebind the keys.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://dev.my-gate.net/

 

anything