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

Author Topic: Recieving more than one Key at the same time?  (Read 6538 times)

0 Members and 1 Guest are viewing this topic.

Sloped

  • Newbie
  • *
  • Posts: 7
    • View Profile
Recieving more than one Key at the same time?
« on: July 05, 2009, 10:09:39 am »
I've been working on my own input system, it works pretty well and I have all of the enterable keys mapped out (aside from the ones that use two inputs) but I seem to have run into a problem, here is my code:

Code: [Select]

if(key == sf::Key::A) return "a";
if(key == sf::Key::A && key == sf::Key::LShift) return "A";


Now the problem is that my input system won't detect both A and LShift or any key and LShift, does anyone know the reason for this and a possible fix?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Recieving more than one Key at the same time?
« Reply #1 on: July 05, 2009, 11:05:30 am »
The problem is that when key == sf::Key::A is true the function return so key == sf::Key::A && key == sf::Key::LShift is never tested.

You can use flag.

Here you use strings as return value. Why don't you use char ? Anyway, flag are the best here.
SFML / OS X developer

Daazku

  • Hero Member
  • *****
  • Posts: 896
    • View Profile
Recieving more than one Key at the same time?
« Reply #2 on: July 05, 2009, 05:37:30 pm »
Why don't you use TextEntered event??
Pensez à mettre le tag [Résolu] une fois la réponse à votre question trouvée.
Remember to add the tag [Solved] when you got an answer to your question.

Sloped

  • Newbie
  • *
  • Posts: 7
    • View Profile
Recieving more than one Key at the same time?
« Reply #3 on: July 06, 2009, 01:41:38 am »
Quote from: "Daazku"
Why don't you use TextEntered event??


I'm testing different ways to do things.

Quote from: "Hiura"
The problem is that when key == sf::Key::A is true the function return so key == sf::Key::A && key == sf::Key::LShift is never tested.

You can use flag.

Here you use strings as return value. Why don't you use char ? Anyway, flag are the best here.


I use a string because during testing I wanted to see different ways i could do different things, such as deleting an entered character and other such things. So when pressing Back it returns a string with the contents of "DEL", my input function takes this, finds the last character in the string and erases it.

What are "flag"s

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Recieving more than one Key at the same time?
« Reply #4 on: July 06, 2009, 04:41:45 am »
Quote

Key events (KeyPressed, KeyReleased)

    * Event.Key.Code contains the code of the key that was pressed / released
    * Event.Key.Alt tells whether or not Alt key is pressed
    * Event.Key.Control tells whether or not Control key is pressed
    * Event.Key.Shift tells whether or not Shift key is pressed

I think you could use Event.Key.Shift to see if Shift is pressed with the key

Sloped

  • Newbie
  • *
  • Posts: 7
    • View Profile
Recieving more than one Key at the same time?
« Reply #5 on: July 06, 2009, 06:03:25 am »
Quote from: "Astrof"
Quote

Key events (KeyPressed, KeyReleased)

    * Event.Key.Code contains the code of the key that was pressed / released
    * Event.Key.Alt tells whether or not Alt key is pressed
    * Event.Key.Control tells whether or not Control key is pressed
    * Event.Key.Shift tells whether or not Shift key is pressed

I think you could use Event.Key.Shift to see if Shift is pressed with the key



Ah thanks, I completely forgot about Event.Key.Shift

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Recieving more than one Key at the same time?
« Reply #6 on: July 06, 2009, 12:00:36 pm »
Quote from: "Sloped"
I use a string because during testing I wanted to see different ways i could do different things, such as deleting an entered character and other such things. So when pressing Back it returns a string with the contents of "DEL", my input function takes this, finds the last character in the string and erases it.
The "problem" of string in such a system is copying. You lose performance.

Quote from: "Sloped"
What are "flag"s
I don't have any English tutor about that, sorry, but you can find them on Google with these keywords : bits flags C, I think.
SFML / OS X developer

Sloped

  • Newbie
  • *
  • Posts: 7
    • View Profile
Recieving more than one Key at the same time?
« Reply #7 on: July 06, 2009, 01:33:01 pm »
Quote from: "Hiura"
Quote from: "Sloped"
I use a string because during testing I wanted to see different ways i could do different things, such as deleting an entered character and other such things. So when pressing Back it returns a string with the contents of "DEL", my input function takes this, finds the last character in the string and erases it.
The "problem" of string in such a system is copying. You lose performance.

Quote from: "Sloped"
What are "flag"s
I don't have any English tutor about that, sorry, but you can find them on Google with these keywords : bits flags C, I think.


Thanks, but as I said it's testing to find better ways to do tihngs or more dynamic ways :wink:

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Recieving more than one Key at the same time?
« Reply #8 on: July 06, 2009, 11:26:56 pm »
You could get the unicode char from TextEntered.
As unicode (UTF-8/16/32) is backward compatible with ANSI, you can do a (character&(~0x7f) == 0) to check if it's an ANSI character and then use it safely as ANSI.

It takes into account everything, like acutes used in most Latin languages, and specific characters that you don't probably know about that need a special escaping sequence (like the portuguese C with cedilla: Ç).

It's the best way AFAIK.

Regards
-Martín

Sloped

  • Newbie
  • *
  • Posts: 7
    • View Profile
Recieving more than one Key at the same time?
« Reply #9 on: July 07, 2009, 04:05:15 am »
Thanks I'll definitely try that.

 

anything