SFML community forums
Help => Window => Topic started 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:
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?
-
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.
-
Why don't you use TextEntered event??
-
Why don't you use TextEntered event??
I'm testing different ways to do things.
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
-
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
-
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
-
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.
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.
-
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.
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:
-
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
-
Thanks I'll definitely try that.