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

Author Topic: Can't detect LShift / RShift in one time  (Read 4727 times)

0 Members and 1 Guest are viewing this topic.

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Can't detect LShift / RShift in one time
« 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;
        }
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Can't detect LShift / RShift in one time
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: Can't detect LShift / RShift in one time
« Reply #2 on: May 12, 2015, 12:47:40 pm »
No, have only my old classic keyboard Mitsumi win95.


Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Can't detect LShift / RShift in one time
« Reply #3 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: Can't detect LShift / RShift in one time
« Reply #4 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.
« Last Edit: May 12, 2015, 04:54:29 pm by Redee »

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: Can't detect LShift / RShift in one time
« Reply #5 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.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Can't detect LShift / RShift in one time
« Reply #6 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 function. Also check the tutorial about inputs if needed.

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: Can't detect LShift / RShift in one time
« Reply #7 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 function. Also check the tutorial about inputs 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.
« Last Edit: May 13, 2015, 02:38:15 pm by Redee »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Can't detect LShift / RShift in one time
« Reply #8 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:
  • If you hold LShift, then RShift, then release LShift, no LShift Released event will be triggered. The key repeating will stop for a bit, but no Released event for LShift. If you then also release RShift it will trigger a Released event for RShift.
  • If you hold LShift, then RShift, then release RShift, no RShift Released event will be triggered and no key gets repeated as expected. If you then also release LShift it will trigger a Released event for LShift.

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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Redee

  • Jr. Member
  • **
  • Posts: 97
    • View Profile
Re: Can't detect LShift / RShift in one time
« Reply #9 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.
« Last Edit: May 13, 2015, 08:11:50 pm by Redee »

 

anything