SFML community forums

Help => General => Topic started by: doomista on May 01, 2017, 11:45:06 pm

Title: Release pressed key programatically
Post by: doomista on May 01, 2017, 11:45:06 pm
Hi, is there a way to programatically release a pressed key on a keyboard/joystick so functions like isKeyPressed won't return true unless the player releases that key physically and presses it again?

I wrote myself a wrapper module that allows seamless switching between keyboard and X360 controller and it is meant to work without the need of handling events and this little bit is the last thing I need to finish it.

Thanks for help
Title: Re: Release pressed key programatically
Post by: Hapax on May 02, 2017, 12:03:14 am
isKeyPressed is the current state of that device so changing it makes no sense.

However, you can use a boolean to track that it's been released and take it as not pressed until it's reset:
bool released{ false };

if (isKeyPressed && !released)
{
    // key pressed
}

if (!isKeyPressed)
    released = false;

if (iWantToForceItToRelease)
    released = true;
Title: Re: Release pressed key programatically
Post by: doomista on May 02, 2017, 03:23:00 pm
Thank you for clarification :)