SFML community forums

Help => Window => Topic started by: Sloped on July 05, 2009, 10:09:39 am

Title: Recieving more than one Key at the same time?
Post by: Sloped 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?
Title: Recieving more than one Key at the same time?
Post by: Hiura 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.
Title: Recieving more than one Key at the same time?
Post by: Daazku on July 05, 2009, 05:37:30 pm
Why don't you use TextEntered event??
Title: Recieving more than one Key at the same time?
Post by: Sloped 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
Title: Recieving more than one Key at the same time?
Post by: Astrof 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
Title: Recieving more than one Key at the same time?
Post by: Sloped 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
Title: Recieving more than one Key at the same time?
Post by: Hiura 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.
Title: Recieving more than one Key at the same time?
Post by: Sloped 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:
Title: Recieving more than one Key at the same time?
Post by: nitram_cero 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
Title: Recieving more than one Key at the same time?
Post by: Sloped on July 07, 2009, 04:05:15 am
Thanks I'll definitely try that.