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

Author Topic: Non-English keyboards for an English text-based game  (Read 2334 times)

0 Members and 1 Guest are viewing this topic.

yparghi

  • Newbie
  • *
  • Posts: 24
  • Maker of the adventure game K Station
    • View Profile
    • K Station
Non-English keyboards for an English text-based game
« on: May 08, 2016, 08:05:32 pm »
I'm making an adventure game where you type in text commands in English, like this:



I know this is broad, but are there any specific practices or considerations to handle non-English keyboard layouts in my code?

My command input only accepts a-z, 0-9, space, and backspace, so per the SFML tutorial my game loop looks like this:

      if (event.type == sf::Event::TextEntered) {
        if (event.text.unicode < 128) {
          char charEntered = static_cast<char>(event.text.unicode);
          if ((charEntered >= 'A' && charEntered <= 'Z')
              || (charEntered >= 'a' && charEntered <= 'z')
              || (charEntered >= '0' && charEntered <= '9')
              || charEntered == ' '
              || charEntered == '\b') {
            // Show the next letter...
          }
        }
      }
 

In other words, I toss out everything except a handful of ASCII chars.

Does anyone see any pitfalls in this approach with respect to foreign keyboards? Do you think this is generally sufficient so that someone using a French layout, or a bilingual Hindi/English keyboard, will be able to type in English correctly?

I'm not well versed in internationalization issues, so any non-English insight is appreciated.
K Station: An adventure game of disappearing lives | Out now on Steam! | Twitter @yashparghi

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
AW: Non-English keyboards for an English text-based game
« Reply #1 on: May 08, 2016, 08:13:05 pm »
SFML unfortunately still doesn't have proper keycodes, but I think your code should do the trick. ;)
Except that I'm not sure if the unicode <=> char conversion will always work.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Non-English keyboards for an English text-based game
« Reply #2 on: May 08, 2016, 09:33:16 pm »
I see nothing wrong with this code. The advantage of the TextEntered event is that it completely abstracts the keyboard layout and input method, it just gives you the resulting character.
Laurent Gomila - SFML developer

yparghi

  • Newbie
  • *
  • Posts: 24
  • Maker of the adventure game K Station
    • View Profile
    • K Station
Re: Non-English keyboards for an English text-based game
« Reply #3 on: May 08, 2016, 09:55:43 pm »
Okay, thank you both. I suspected it was straightforward, I just wanted a second opinion.
K Station: An adventure game of disappearing lives | Out now on Steam! | Twitter @yashparghi

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Non-English keyboards for an English text-based game
« Reply #4 on: May 10, 2016, 02:57:56 pm »
I'd simplify it a bit by using "iswalnum()", which allows you to skip all the comparisons except space and backspace.