Single KeyPress

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Murloc992
Posts: 272
Joined: Mon Apr 13, 2009 2:45 pm
Location: Utena,Lithuania

Single KeyPress

Post by Murloc992 »

Yo, a nooby problem/question here. Is it possible to make a single key press/key release action in event receiver? Bcz now I have a key press/release which tend to spam my key.. a lot... If yes, any suggestions?

Thanks in advance!
CuteAlien
Admin
Posts: 9679
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Sorry no. You have to handle that currently yourself. You might be able to disable key-repeat with OS system-functions. I think we had a thread about that recently and I think we should offer either some way to disable that in Irrlicht or add another flag to the key-event so people find out if it's a repeat key or not (but not sure right now if that info is easy to get on all systems - I think we can get it on Windows, not sure on X11 right now).

So if you add a feature request for that into the feature-request tracker you can help us not to forget that.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

and until then you could do something similar to this:

Code: Select all

bool CStateMenu::OnKeyInputEvent(const irr::SEvent &e)
{
  if (!e.KeyInput.PressedDown)
  {
    switch (e.KeyInput.Key)
    {
      case KEY_ESCAPE :
      {
        // something
      } break;
    }
  }

  keys[e.KeyInput.Key] = e.KeyInput.PressedDown;
  return false;
}
so it triggers onRelease
Never take advice from someone who likes to give advice, so take my advice and don't take it.
humbrol
Posts: 83
Joined: Sun Nov 18, 2007 8:22 pm

Post by humbrol »

may be a dumb idea but could you set a timer to see if a second had passed
if so then if the key is pressed set a bool to true if false and false if true?

if(deltatime > 1000)
{
if(keypressed = TRUE)
keypressed = FALSE)
else
keypressed = TRUE
}

nor meant to run, but just tossing a idea out..
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

just had another idea which is pretty much exactly what you want:
you just need a bool var in your eventreceiver (set false on startup in the constructor)

Code: Select all

// member var of eventreceiver
bool OnceDone = false;

Code: Select all

// key input function
bool OnKeyInputEvent(const irr::SEvent &e)
{
  if (!e.KeyInput.PressedDown) OnceDone = false;

  if (e.KeyInput.PressedDown && !OnceDone)
  {
    switch (e.KeyInput.Key)
    {
      case KEY_ESCAPE :
      {
        // do something here
        OnceDone = true;
      } break;
    }
  }

  return false;
}
Never take advice from someone who likes to give advice, so take my advice and don't take it.
Post Reply