SFML community forums

Help => Window => Topic started by: dathoedezt on March 25, 2011, 07:54:23 pm

Title: event for keypresses
Post by: dathoedezt on March 25, 2011, 07:54:23 pm
Code: [Select]
      switch (event->Type) {
          case sf::Event::KeyPressed:
            OnKeyPress(event->Key.Code, event->Key.Alt, event->Key.Control, event->Key.Shift);
            break;
       }


Code: [Select]
   void OnKeyPress(sf::Key::Code key, bool alt, bool ctrl, bool shift) {
        // doesnt work
        if (key == sf::Key::Num1) {
            DoSomething();
        }
        // does work
        if (key == sf::Key::F1) {
            DoSomethingElse();
        }
    }


is there some reason doing it the way i am that will cause F1 to work but none the others ive tested?
tried Num1, Numpad1, & A but testing for any F key will work...
Title: event for keypresses
Post by: dathoedezt on March 26, 2011, 06:28:39 pm
okay... letter and number keys work with a sf::Event::TextEntered.

so is it possible to get letter and number keys from sf::Event::KeyPressed?
Title: event for keypresses
Post by: Groogy on March 26, 2011, 07:00:24 pm
Sounds weird, should work but kind of hard to see the whole picture from what you have given us. Though why is event a pointer?
Title: event for keypresses
Post by: dathoedezt on March 27, 2011, 12:23:17 am
i had my Event in a class derived from RenderWindow and used a pointer to the event in a class to process the events, my "scenes" were derived from the event class i made so i just overload those functions for when events were triggered.

uh yea seems weird to me that checking letter and number keys outside the class event was created didnt work but f and other keys still worked :-/
unless im just missing something fundamental which could be possible lol

i just moved a sf::Event in my "scenes" and seems to work now although unsure if that will cause issues in future when i try switch between them