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

Author Topic: Event.Key.Code to correct ASCI CODE  (Read 13121 times)

0 Members and 2 Guests are viewing this topic.

guvidu

  • Newbie
  • *
  • Posts: 4
    • View Profile
Event.Key.Code to correct ASCI CODE
« on: April 18, 2008, 04:44:22 pm »
Hi - im having a problem with Event.Key.Code

I need it to return the correct Asci code - and right now (im using the latest version from SVN) - it only return good asci code for chars.

exemple SFML key " . " = 270
             ASCII CODE   = 46

the problem is i dont see a rule in this codes so i could convert it myself
Can you help me figure out how to convert Event.key.code to correct ASCII ?

Thanks

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Event.Key.Code to correct ASCI CODE
« Reply #1 on: April 22, 2008, 03:17:12 pm »
Why can't you write a function in your app to do it yourself?

aisman

  • Newbie
  • *
  • Posts: 25
    • View Profile
Event.Key.Code to correct ASCI CODE
« Reply #2 on: April 22, 2008, 04:17:31 pm »
Quote from: "quasius"
Why can't you write a function in your app to do it yourself?

Using a standard is better as define some new non standards.
That is the reason why it existing standards on the world.
one of this standards is the ASCII.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Event.Key.Code to correct ASCI CODE
« Reply #3 on: April 22, 2008, 05:09:39 pm »
But the SFML key codes don't have to follow any standard (or I could use EBCDIC just to bother you), so just do the conversion on your side using a big switch or a table. Plus, it will be more robust on your side the day I decide to add a new code in the middle of the enumeration.

I don't see what's the problem with this.

If you want to get real characters from the input, rather use sf::Event::TextEntered which is done exactly for that and will give you UTF-16 standard.
Laurent Gomila - SFML developer

nakee

  • Newbie
  • *
  • Posts: 1
    • ICQ Messenger - 6117754
    • View Profile
Suggestion for function
« Reply #4 on: December 30, 2008, 09:36:40 am »
Code: [Select]

void SFKeyToString(unsigned int keycode, char *keyStr) {
    switch (keycode) {
    case sf::Key::Escape: sprintf(keyStr, "Escape"); break;
    case sf::Key::LControl: sprintf(keyStr, "LControl"); break;
    case sf::Key::LShift: sprintf(keyStr, "LShift"); break;
    case sf::Key::LAlt: sprintf(keyStr, "LAlt"); break;
    case sf::Key::LSystem: sprintf(keyStr, "LSystem"); break;
    case sf::Key::RControl: sprintf(keyStr, "RControl"); break;
    case sf::Key::RShift: sprintf(keyStr, "RShift"); break;
    case sf::Key::RAlt: sprintf(keyStr, "RAlt"); break;
    case sf::Key::RSystem: sprintf(keyStr, "RSystem"); break;
    case sf::Key::Menu: sprintf(keyStr, "Menu"); break;
    case sf::Key::LBracket: sprintf(keyStr, "LBracket"); break;
    case sf::Key::RBracket: sprintf(keyStr, "RBracket"); break;
    case sf::Key::SemiColon: sprintf(keyStr, ";"); break;
    case sf::Key::Comma: sprintf(keyStr, ","); break;
    case sf::Key::Period: sprintf(keyStr, "."); break;
    case sf::Key::Quote: sprintf(keyStr, "\'"); break;
    case sf::Key::Slash: sprintf(keyStr, "/"); break;
    case sf::Key::BackSlash: sprintf(keyStr, "\\"); break;
    case sf::Key::Tilde: sprintf(keyStr, "~"); break;
    case sf::Key::Equal: sprintf(keyStr, "="); break;
    case sf::Key::Dash: sprintf(keyStr, "-"); break;
    case sf::Key::Space: sprintf(keyStr, "Space"); break;
    case sf::Key::Return: sprintf(keyStr, "Return"); break;
    case sf::Key::Back: sprintf(keyStr, "Back"); break;
    case sf::Key::Tab: sprintf(keyStr, "Tab"); break;
    case sf::Key::PageUp: sprintf(keyStr, "Page Up"); break;
    case sf::Key::PageDown: sprintf(keyStr, "Page Down"); break;
    case sf::Key::End: sprintf(keyStr, "End"); break;
    case sf::Key::Home: sprintf(keyStr, "Home"); break;
    case sf::Key::Insert: sprintf(keyStr, "Insert"); break;
    case sf::Key::Delete: sprintf(keyStr, "Delete"); break;
    case sf::Key::Add: sprintf(keyStr, "+"); break;
    case sf::Key::Subtract: sprintf(keyStr, "-"); break;
    case sf::Key::Multiply: sprintf(keyStr, "*"); break;
    case sf::Key::Divide: sprintf(keyStr, "/"); break;
    case sf::Key::Left: sprintf(keyStr, "Left"); break;
    case sf::Key::Right: sprintf(keyStr, "Right"); break;
    case sf::Key::Up: sprintf(keyStr, "UP"); break;
   case sf::Key::Down: sprintf(keyStr, "Down"); break;
    case sf::Key::Numpad0: sprintf(keyStr, "NP 0"); break;
    case sf::Key::Numpad1: sprintf(keyStr, "NP 1"); break;
    case sf::Key::Numpad2: sprintf(keyStr, "NP 2"); break;
    case sf::Key::Numpad3: sprintf(keyStr, "NP 3"); break;
    case sf::Key::Numpad4: sprintf(keyStr, "NP 4"); break;
    case sf::Key::Numpad5: sprintf(keyStr, "NP 5"); break;
    case sf::Key::Numpad6: sprintf(keyStr, "NP 6"); break;
    case sf::Key::Numpad7: sprintf(keyStr, "NP 7"); break;
    case sf::Key::Numpad8: sprintf(keyStr, "NP 8"); break;
    case sf::Key::Numpad9: sprintf(keyStr, "NP 9"); break;
    case sf::Key::F1: sprintf(keyStr, "F1"); break;
    case sf::Key::F2: sprintf(keyStr, "F2"); break;
    case sf::Key::F3: sprintf(keyStr, "F3"); break;
    case sf::Key::F4: sprintf(keyStr, "F4"); break;
    case sf::Key::F5: sprintf(keyStr, "F5"); break;
    case sf::Key::F6: sprintf(keyStr, "F6"); break;
    case sf::Key::F7: sprintf(keyStr, "F7"); break;
    case sf::Key::F8: sprintf(keyStr, "F8"); break;
    case sf::Key::F9: sprintf(keyStr, "F9"); break;
    case sf::Key::F10: sprintf(keyStr, "F10"); break;
    case sf::Key::F11: sprintf(keyStr, "F11"); break;
    case sf::Key::F12: sprintf(keyStr, "F12"); break;
    case sf::Key::F13: sprintf(keyStr, "F13"); break;
    case sf::Key::F14: sprintf(keyStr, "F14"); break;
    case sf::Key::F15: sprintf(keyStr, "F15"); break;
    case sf::Key::Pause: sprintf(keyStr, "Paues"); break;
       
    default:
        sprintf(keyStr, "%c", keycode);
    }
}

bobwilson

  • Newbie
  • *
  • Posts: 1
    • View Profile
Event.Key.Code to correct ASCI CODE
« Reply #5 on: August 23, 2010, 11:01:15 am »
Quote from: "Laurent"
But the SFML key codes don't have to follow any standard (or I could use EBCDIC just to bother you), so just do the conversion on your side using a big switch or a table. Plus, it will be more robust on your side the day I decide to add a new code in the middle of the enumeration.

I don't see what's the problem with this.

If you want to get real characters from the input, rather use sf::Event::TextEntered which is done exactly for that and will give you UTF-16 standard.


I was VERY unimpressed with that statement.  If you are the dev of SFML you should know that there are extraneous situations that may call for such a function.  Not only that, but implementing such functionality should be (by any standard) the libraries job.

I hire programmers left and right.  One of the biggest things I look for in a programmer is the ability to recognize possible situations where certain functionality may be required and to implement it beforehand.

If you where applying for a job at my company I would not hire you because you failed that criteria.  Miserably.

Spidyy

  • Sr. Member
  • ****
  • Posts: 493
    • View Profile
Event.Key.Code to correct ASCI CODE
« Reply #6 on: August 23, 2010, 03:31:50 pm »
But I don't think laurent were appying to your company. :] Or are you searching for recruits in this forum instead of help or giving help with SFML? :p (I'm not looking to anger you but your own statement looks a bit aggressive.)

Anyway, I'm not using ASCII or EBCDIC or whatever standard exist in my game. Key codes enumerator fairly do the job by themselves. This way you can write your own conversion algorithm, from your own needs.

It is a mark of SFML to be easily manipulated (see features web page), so that users can make their own implementations. :p

And the one rule Laurent is using is to avoid functions that will be usefull for few users. He repeated it itself many times enough through in suggestions and features asking. :p

dunce

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Event.Key.Code to correct ASCI CODE
« Reply #7 on: August 23, 2010, 05:44:57 pm »
Terrific! Laurent just has lost all chances of being hired!

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Event.Key.Code to correct ASCI CODE
« Reply #8 on: August 24, 2010, 09:22:51 pm »
Ho yes! He will work for us FOR EVER!!  :twisted:
SFML / OS X developer

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Event.Key.Code to correct ASCI CODE
« Reply #9 on: August 25, 2010, 08:11:37 am »
And he already mentioned that TextEntered does the job. :) Of course you get UTF-16 values, however the ASCII set is included there, so basically you can check for a "if( x < 128 ) { // I'm ASCII }".

 

anything