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

Author Topic: event for keypresses  (Read 2114 times)

0 Members and 1 Guest are viewing this topic.

dathoedezt

  • Newbie
  • *
  • Posts: 9
    • View Profile
event for keypresses
« 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...

dathoedezt

  • Newbie
  • *
  • Posts: 9
    • View Profile
event for keypresses
« Reply #1 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?

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
event for keypresses
« Reply #2 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?
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

dathoedezt

  • Newbie
  • *
  • Posts: 9
    • View Profile
event for keypresses
« Reply #3 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