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

Author Topic: Logical link between sf::keyboard and ASCI/UNICODE tables?  (Read 5425 times)

0 Members and 1 Guest are viewing this topic.

mutonizer

  • Newbie
  • *
  • Posts: 8
    • View Profile
Logical link between sf::keyboard and ASCI/UNICODE tables?
« on: July 20, 2012, 09:07:15 am »
Morning,

Are there any SFML 2.0 function (or logic) to convert the sf::keyboard enum to an ASCI or UNICODE character table?

The idea is to be able to initialize a class (which is just to display sf:text, but with all events handling taken care of, etc) with a character, to make it a shortcut, and have the class handle the function to automatically edit the text and make all appropriate changes, like adding for example a "a) " in front of the current label text if we set that shortcut to "a", then react through events using sf::keyboard isPressed.

I've been using sf::keyboard to avoid tons of boolean stuff everytime sf::event:keyPressed pops up, but I'm having issues finding a logical conversion between the actual UNICODE key code, and sf::keyboard enum values and I can't just initialize with the enum directly, since I need to display the character in question.

So the question is, before I start doing my personal conversion function, is there already one in place?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Logical link between sf::keyboard and ASCI/UNICODE tables?
« Reply #1 on: July 20, 2012, 09:37:08 am »
Use the sf::Event::TextEntered for text input, not key press.
Laurent Gomila - SFML developer

mutonizer

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Logical link between sf::keyboard and ASCI/UNICODE tables?
« Reply #2 on: July 20, 2012, 10:30:09 am »
Hey,

err, I do, but fail to see how it relates to what I posted. Probably didn't explain myself properly. :)

Say I want the user to be able to press A and click somewhere, and it does something.

Instead of storing a bool on keypress/keyrelease, I wanted to use sf::keyboard, which gives direct access to the keyboard state so I can just, on the Mousebutton event, check if sf::keyboard::a is pressed and that's it.

But add to that for example that I want to display, on click, the letter A somewhere (or any letter being pressed when mousebutton event pops up). My problem is that from the mousebutton event (where action is taken), I can know if the letter A is pressed, but how can I use that information, to know which letter to display?

I could make my own conversion function, inputting the sf::keyboard value and returning the converted ASCI value, but is there already such conversion function or any logic to the sf::keyboard enum relating to the ASCI/UNICODE tables?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Logical link between sf::keyboard and ASCI/UNICODE tables?
« Reply #3 on: July 20, 2012, 10:46:05 am »
No, there's no such function. You have to write it with a big switch.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10976
    • View Profile
    • development blog
    • Email
Re: Logical link between sf::keyboard and ASCI/UNICODE tables?
« Reply #4 on: July 20, 2012, 10:54:09 am »
You have to write it with a big switch.
Or figure out a formula that converts key codes from the key enum to your chars.
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: Logical link between sf::keyboard and ASCI/UNICODE tables?
« Reply #5 on: July 20, 2012, 11:01:56 am »
Quote
Or figure out a formula that converts key codes from the key enum to your chars.
How? SFML key codes are defined randomly and might change in the future. You can't find a single formula that maps all key codes to ASCII/Unicode values. You must map them one by one.
Laurent Gomila - SFML developer

mutonizer

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Logical link between sf::keyboard and ASCI/UNICODE tables?
« Reply #6 on: July 20, 2012, 12:09:00 pm »
Cheers.

Just wanted to be sure to avoid doing it only to find out later on that it was already present.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Logical link between sf::keyboard and ASCI/UNICODE tables?
« Reply #7 on: July 20, 2012, 06:37:41 pm »
I could make my own conversion function, inputting the sf::keyboard value and returning the converted ASCI value, but is there already such conversion function or any logic to the sf::keyboard enum relating to the ASCI/UNICODE tables?
You can take a look at Thor's InputNames. The functions map the keys and mouse buttons to a string (the enumerator name) or vice versa.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything