Jump to content
  • Advertisement
Sign in to follow this  
FGFS

user input key store in array

This topic is 2179 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


Why don't you just use the event and directly react to it?

Depending on the requirements, this could be ideal. However in many cases at this point in the program you don't know which entities / gameobjects / nodes need to react to the control so it is required to store a "snapshot" of keys which can be polled during the individual objects update / control events.

 

In the system I presented above, the last keys pressed this frame are stored in Input::downKeys.

The keys released during last frame are stored in Input::upKeys

and the current keys held down are stored in Input::keys

 

(This is mimicking the same API that Unity 3D provides (as is the nature of this project ;))).

 

So to get the last 4 keys pressed, just iterate through the last 4 keys in the Input::downKeys array.

This approach is pretty much platform agnostic so for x-plane, just substitute event.key.keysym.sym with gChar in whatever bit of code you get the key down event.

Edited by Karsten_

Share this post


Link to post
Share on other sites
Advertisement

Hmm if I do:

 

static std::vector<char> keys;
static std::vector<int> upKeys;
static std::vector<int> downKeys;

 

 

    hasControlFlag = gFlags & xplm_ControlFlag;
    hasDownFlag = gFlags & xplm_DownFlag;

      if (hasOptAltFlag == 1)
      {
          keys.pop_back();
      }

if (hasControlFlag == 1)
{
    if (hasDownFlag == 1)
    {
    keys.push_back(gChar);
}
for (std::vector<char>::iterator it = keys.begin() ; it != keys.end(); ++it)
//for (std::vector<char>::iterator it = 0; it != 5; ++it)
{
      std::copy(keys.begin(), keys.end(), ApEntrystr);
}

    RenderText(font, 1, 1, 1, PanelLeft1 + 550, PanelTop1 - 320, test.displayAirport(ApEntrystr));
        }

 

pusing ctrl and a key not only fills the vector but it displays also lots of rubbish and it crashes after a while.

Thanks again.

Edited by FGFS

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!