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

Author Topic: sf::Input and keypress repeat problem  (Read 3565 times)

0 Members and 2 Guests are viewing this topic.

JordyD

  • Newbie
  • *
  • Posts: 10
    • View Profile
sf::Input and keypress repeat problem
« on: August 10, 2009, 01:49:21 am »
I'm using SFML 1.4 on Ubuntu 9.04.

It seems when I use this code:
Code: [Select]
if (Input.IsKeyDown(sf::Key::A))
        OffsetDirection(1);
if (Input.IsKeyDown(sf::Key::D))
        OffsetDirection(-1);

and press and hold the 'D' or 'A' key, it calls OffsetDirection once, pauses, then calls it continuously as if I was holding the key down (which I am). But I don't want it to pause. Is this normal behavior for sf::Input? If it is, is there something I can use as an alternative that doesn't pause?

By the way, if I configure my computer to have no delay between key press repeating through System>Preferences>Keyboard, then this problem goes away. But I don't want to have to have anybody that wants to use my program to have to toggle their system preferences.

I've tried doing this as an alternative:

Code: [Select]

// outside the main loop
struct KeysPressed {
        bool A;
        bool B;
} KeysPressed;
...
// inside the main loop
if (Event.Type == sf::Event::KeyPressed)
{
        switch (Event.Key.Code)
        {
        case sf::Key::A:
                KeysPressed.A = true;
                break;
        case sf::Key::D:
                KeysPressed.D = true;
                break;
        default:
                break;
        }
}
else if (Event.Type == sf::Event::KeyReleased)
{
        switch (Event.Key.Code)
        {
        case sf::Key::A:
                KeysPressed.A = false;
                break;
        case sf::Key::D:
                KeysPressed.D = false;
                break;
        default:
                break;
        }
}

if (KeysPressed.A == true)
        OffsetDirection(1);
if (KeysPressed.D == true)
        OffsetDirection(-1);


But the problem persists.

Any help would be appreciated.

Thanks,
Jordy

EDIT: I deleted this from System and reposted here, because I realized I posted in the wrong section. Sorry.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Input and keypress repeat problem
« Reply #1 on: August 10, 2009, 07:44:10 am »
You should try updating to version 1.5.
Laurent Gomila - SFML developer

JordyD

  • Newbie
  • *
  • Posts: 10
    • View Profile
sf::Input and keypress repeat problem
« Reply #2 on: August 10, 2009, 04:58:14 pm »
I upgraded to version 1.5, but the problem is still there.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Input and keypress repeat problem
« Reply #3 on: August 10, 2009, 05:08:15 pm »
This is weird because there is code to explicitely get rid of this behaviour in the Linux implementation.

And, as far as I know, you're the only one to report such a behaviour. Is there anything exotic on your Ubuntu?
Laurent Gomila - SFML developer

JordyD

  • Newbie
  • *
  • Posts: 10
    • View Profile
sf::Input and keypress repeat problem
« Reply #4 on: August 10, 2009, 05:17:27 pm »
I don't think there is anything exotic on my Ubuntu. I tried disabling Compiz, but it didn't change anything. If I think of something I'll let you know.