SFML community forums

Help => Window => Topic started by: Niely on October 05, 2015, 12:09:29 pm

Title: Can't check LControl or RControl
Post by: Niely on October 05, 2015, 12:09:29 pm
Hi

I'm encountering a problem.
I want to check if the user presses the left Control (Ctrl) key.

But it ain't working.
This is my code:
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::LControl) || sf::Keyboard::isKeyPressed(sf::Keyboard::Key::RControl)) {
                                                //SFML Error
                                                switch(character) {
                                                        case 13:
                                                                //Send as FIRST!!!
                                                                cout << "pressed"<<endl;
                                                                break;
                                                }
                                        }

But, what I find weird:
When I replace LControl with "Left", it's working perfectly. It only ain't working with Shift or Alt.

To be more clear, I'm using:
Asus X555LD,
Azerty keyboard-layout,
Windows 8.1,
Visual Studio 2015 Enterprise,
SFML 2.3.2.

It can't be a problem because of if/else-if orders, because I get the exact same result when placing that block on top. So, is this a problem of me, my hardware, or SFML? And how to fix it?

Thanks!
Title: Re: Can't check LControl or RControl
Post by: Rhimlock on October 05, 2015, 12:29:39 pm
You should not mix pollEvent and isKeyPressed.

In your Key-Event, you have members for "alt", "control" and "shift"

http://www.sfml-dev.org/documentation/2.3.2/structsf_1_1Event_1_1KeyEvent.php (http://www.sfml-dev.org/documentation/2.3.2/structsf_1_1Event_1_1KeyEvent.php)
Title: Re: Can't check LControl or RControl
Post by: Hapax on October 12, 2015, 06:39:34 pm
It can't be a problem because of if/else-if orders, because I get the exact same result when placing that block on top.
Is LControl tested at all before this if block?

You should not mix pollEvent and isKeyPressed.
There is no pollEvent in this code.