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

Author Topic: Release pressed key programatically  (Read 1214 times)

0 Members and 1 Guest are viewing this topic.

doomista

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Release pressed key programatically
« 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

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Release pressed key programatically
« Reply #1 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;
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

doomista

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Release pressed key programatically
« Reply #2 on: May 02, 2017, 03:23:00 pm »
Thank you for clarification :)

 

anything