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

Author Topic: sf::Event return key pressed  (Read 6881 times)

0 Members and 1 Guest are viewing this topic.

tntexplosivesltd

  • Full Member
  • ***
  • Posts: 163
    • View Profile
sf::Event return key pressed
« on: May 27, 2011, 05:17:44 pm »
Hi there
Is there any way to get sf::Event to return the scancode of the key that was pressed?
Thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Event return key pressed
« Reply #1 on: May 27, 2011, 06:06:08 pm »
No.

What do you want to do with a scan code?
Laurent Gomila - SFML developer

tntexplosivesltd

  • Full Member
  • ***
  • Posts: 163
    • View Profile
sf::Event return key pressed
« Reply #2 on: May 27, 2011, 06:07:43 pm »
Well, I want to make it so that the user can type in a text area.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Event return key pressed
« Reply #3 on: May 27, 2011, 06:12:08 pm »
And how would a scan code help implementing this?

sf::Event::TextEntered is what you're looking for.
Laurent Gomila - SFML developer

tntexplosivesltd

  • Full Member
  • ***
  • Posts: 163
    • View Profile
sf::Event return key pressed
« Reply #4 on: May 28, 2011, 05:08:28 am »
Hmm, that uses unicode. I am only wanting to use ASCII (I am writing my own text methods with OpenGL).

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
sf::Event return key pressed
« Reply #5 on: May 28, 2011, 05:43:28 am »
Quote from: "tntexplosivesltd"
Hmm, that uses unicode. I am only wanting to use ASCII (I am writing my own text methods with OpenGL).
Unicode's first 128 characters (0x00 to 0x7F) are equivalent to ASCII. Just discard any characters greater than 127.
I use the latest build of SFML2

tntexplosivesltd

  • Full Member
  • ***
  • Posts: 163
    • View Profile
sf::Event return key pressed
« Reply #6 on: May 28, 2011, 06:10:29 am »
Nono, the whole point of me using ASCII was for the extended ASCII.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Event return key pressed
« Reply #7 on: May 28, 2011, 10:08:31 am »
"Extended ASCII" alone doesn't mean anything. There are many different extended ASCII encodings.

And I still don't see how scan codes may help you...
Laurent Gomila - SFML developer

tntexplosivesltd

  • Full Member
  • ***
  • Posts: 163
    • View Profile
sf::Event return key pressed
« Reply #8 on: May 28, 2011, 11:44:38 am »
I realised I don't need scan codes, I need to get the character that the user entered.
I know about extended ASCII, I am using the extended Windows-1252 set (the most common I am told).
So I need to find out what ASCII character the user endered in. I'm not sure how european keyboards differ from ours, so I might just be able to use UTF-8 (well, the first 127 characters of UTF-32). I users to be able to use the letters with accents and thinks like that, if they need to.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Event return key pressed
« Reply #9 on: May 28, 2011, 12:15:56 pm »
Why do you make things so complicated? Just keep a Unicode encoding; SFML gives you UTF-32 characters but you can easily convert to UTF-8 or UTF-16. It depends what classes you use to display your text, and what encodings it can work with.
Laurent Gomila - SFML developer

tntexplosivesltd

  • Full Member
  • ***
  • Posts: 163
    • View Profile
sf::Event return key pressed
« Reply #10 on: May 28, 2011, 01:06:50 pm »
To display the text, I am using OpenGL display lists. I have a Windows-1252 extended character-set texture which I get the character image from. The ascii number of the character represents the display list I need to draw.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Event return key pressed
« Reply #11 on: May 28, 2011, 02:15:09 pm »
Windows-1252 will make things very complicated for you. SFML doesn't provide anything to convert to it, so you'll need to write your own conversion function or find a library or piece of code that does it.

If possible, I suggest you generate a bitmap font using another encoding. Latin-1 (ISO 8859-1) is a good choice: it's defined by the 256 first characters of the Unicode standard, so no conversion is required to convert from UTF-32.
Laurent Gomila - SFML developer

tntexplosivesltd

  • Full Member
  • ***
  • Posts: 163
    • View Profile
sf::Event return key pressed
« Reply #12 on: May 28, 2011, 02:40:51 pm »
Hmm, turns out ISO 8859-1 is Windows-1252, it's just commonly mislabeled as ISO 8859-1. So there's no problem.
So I just need to use a sf::Unicode::UTF32String and turn it into a character array? Or can I use a character array right off the bat? (My function takes a pointer to a character array).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Event return key pressed
« Reply #13 on: May 28, 2011, 02:53:59 pm »
Quote
Hmm, turns out Windows-1252 is ISO 8859-1, it's just commonly mislabeled as ISO 8859-1. So there's no problem.

Oh, indeed you're right. Well, strictly speaking it's not ISO 8859-1, it's an extension to it (it replaces some control characters with printable characters). It's good to know.

Quote
So I just need to use a sf::Unicode::UTF32String and turn it into a character array? Or can I use a character array right off the bat? (My function takes a pointer to a character array).

You can use an array of [unsigned] char directly if you want.
Code: [Select]
std::basic_string<unsigned char> chars;

event loop...
{
    if (event.Type == sf::Event::TextEntered)
    {
        if (event.Text.Unicode < 256)
            chars += static_cast<unsigned char>(event.Text.Unicode);
    }
}
Laurent Gomila - SFML developer

tntexplosivesltd

  • Full Member
  • ***
  • Posts: 163
    • View Profile
sf::Event return key pressed
« Reply #14 on: May 28, 2011, 03:21:10 pm »
Ah cool! Thanks. Is it possible to do it without using the STL? (I'm trying to avoid it - it's horrible at times). Can it be done using just char[]?