SFML community forums

Help => Window => Topic started by: Redee on May 12, 2015, 12:10:02 pm

Title: Can't detect LShift / RShift in one time
Post by: Redee on May 12, 2015, 12:10:02 pm
While LShift and RShift holding and free L(R)Shift - can't detect L(R)Shift release.
Controls and Alts all ok, only shifts can't detect.
Sfml 2.1 (vc++ 2010).
Its can be huge problem like in pinball games, where need to use exactly both shifts.

while(wIn.pollEvent(eV))
{
        if(eV.type == Event::KeyReleased)
        {
                if(eV.key.code == Keyboard::LShift)
                        cout << 111 << endl;
                if(eV.key.code == Keyboard::RShift)
                        cout << 222 << endl;
        }
}
 
Title: AW: Can't detect LShift / RShift in one time
Post by: eXpl0it3r on May 12, 2015, 12:14:16 pm
Did you try different keyboard models? This can easily be a hardware limitation.

When I get home I'll test it.
Title: Re: Can't detect LShift / RShift in one time
Post by: Redee on May 12, 2015, 12:47:40 pm
No, have only my old classic keyboard Mitsumi win95.

(https://farm8.staticflickr.com/7732/17367835499_2cc9144f9f_m.jpg) (https://farm8.staticflickr.com/7732/17367835499_87fed20c5f_o.jpg)
Title: Re: Can't detect LShift / RShift in one time
Post by: Nexus on May 12, 2015, 02:42:06 pm
Do you have a pinball game or anything non-SFML where both shifts work?

You can also search a bit about your keyboard model. Chances are that you're not the first... And if it's a hardware limitation, there's nothing we can do.
Title: Re: Can't detect LShift / RShift in one time
Post by: Redee on May 12, 2015, 02:50:17 pm
Ok now will try find and test other PC Win32 pinball now.


Ok finded Microsoft Pinball Arcade (1998).
There exactly L(R)Shift uses.
When I hold LSh and RSh, and then free LSh - left flipper go down.
Its demonstated when both shifts holds - detected LSh release.

Addiction Pinball (1998) also both shifts normal using.
Title: Re: Can't detect LShift / RShift in one time
Post by: Redee on May 12, 2015, 05:05:00 pm
You can help me to simply check all keys without while(wIn.pollEvent(eV)) ?
Need directly check hold or not every standard key on keyboard.
Title: Re: Can't detect LShift / RShift in one time
Post by: G. on May 12, 2015, 05:47:29 pm
You can detect if a key is currently pressed at any moment with the sf::Keyboard::isKeyPressed (http://www.sfml-dev.org/documentation/2.3/classsf_1_1Keyboard.php#a80a04b2f53005886957f49eee3531599) function. Also check the tutorial about inputs (http://www.sfml-dev.org/tutorials/2.3/window-inputs.php) if needed.
Title: Re: Can't detect LShift / RShift in one time
Post by: Redee on May 12, 2015, 06:35:26 pm
You can detect if a key is currently pressed at any moment with the sf::Keyboard::isKeyPressed (http://www.sfml-dev.org/documentation/2.3/classsf_1_1Keyboard.php#a80a04b2f53005886957f49eee3531599) function. Also check the tutorial about inputs (http://www.sfml-dev.org/tutorials/2.3/window-inputs.php) if needed.

No, its no good like in Moorhunn and action shot  games.
Because need to detect Event ALL TIME !!!
And pinball games too.
F.e. you detect only for short time during beginning of frame.
If you press and release during game world changing logic, your actions logic no detect press of key.

If You want start parallel thread - its will be very expensive for every loop detect keys.

///

But I test for laggy logic of 20fps - for fast press/release shift.
Keyboard::isKeyPressed(Keyboard::LShift)
Keyboard::isKeyPressed(Keyboard::RShift)
Maybe this usefull....

///

But again - no can detect Release key.
For release - can be (Keyboard::isKeyPressed(Keyboard::LShift) == false).

Now i very fast touch shift and some times no detect Shift ispressed.
This is no problem at monitor framerates >= 60 fps.

For pinball no problem because so fast touches no sens....

And for actions shot games no problem too - because all keys detect Release event except only for both shifts in one time.
Title: Re: Can't detect LShift / RShift in one time
Post by: eXpl0it3r on May 13, 2015, 04:27:11 pm
Right I did test the first issue but forgot to actually post then. ;D

Given that your example wasn't complete, I've created my own:

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    sf::RenderWindow window({800, 600}, "Minimal Example");
    window.setVerticalSyncEnabled(true);

    while(window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
            {
                window.close();
            }
            else if(event.type == sf::Event::KeyReleased)
            {
                if(event.key.code == sf::Keyboard::LShift)
                    std::cout << "LShift Released" << std::endl;
                else if(event.key.code == sf::Keyboard::RShift)
                    std::cout << "RShift Released" << std::endl;
                else if(event.key.code == sf::Keyboard::A)
                    std::cout << "A Released" << std::endl;
                else if(event.key.code == sf::Keyboard::D)
                    std::cout << "D Released" << std::endl;
            }
            else if(event.type == sf::Event::KeyPressed)
            {
                if(event.key.code == sf::Keyboard::LShift)
                    std::cout << "LShift Pressed" << std::endl;
                else if(event.key.code == sf::Keyboard::RShift)
                    std::cout << "RShift Pressed" << std::endl;
                else if(event.key.code == sf::Keyboard::A)
                    std::cout << "A Pressed" << std::endl;
                else if(event.key.code == sf::Keyboard::D)
                    std::cout << "D Pressed" << std::endl;
            }
        }

        window.clear();
        window.display();
    }
}

If you press LShift or RShift the Pressed event will trigger correctly and keep repeating as expected and when you release it, it will register it as released.
If you start for example with pressing LShift and then start pressing RShift the RShift will start repeating as expect (e.g. open word and first hold A and then D and only D will get repeated).
Now here is what can be observed:

I've added the same thing for the keys A and D, they do not suffer from this and key released events get triggered properly.

I personally would never bind different actions to right and left shift, however I wonder if this is just a  bug in SFML or if the OS really doesn't report the key release.
Title: Re: Can't detect LShift / RShift in one time
Post by: Redee on May 13, 2015, 08:02:58 pm
Thanks for answer.
Yes my words can sounds crazy, but you see this around shifts )).
Thats why my conclusion > in pinball games - reading Shifts only keyPressed state in beginning of frame.
Not from cumulate array of event actions.

At your OS second "magic" (LSh, RSh, Rsh) no event for Rsh too.
I suppose you tested at Win7, and at my WinXpSp3 exactly same behavior as you see.

And thats why I split logic to all keys and to shifts.
Yes its very rare situation in classic games to press both shifts, but its can be )).

Will be interesting for test OS signal in second "magic" combo.
Or explain me how test it. Where this can be store and from need read.

If no change variable in Win and no change in Sfml - its OS issue.