Thread: SDL C++ Check for a key that is hold down?

  1. #1
    Registered User
    Join Date
    Feb 2013
    Location
    Sweden
    Posts
    171

    Question SDL C++ Check for a key that is hold down?

    Hi! I'm using SDL to try to create a Run and Shoot game. But I do not know how to check if a key is down while the user is HOLDING it.

    I do know how to check if a key was pressed.

    I have tried with the "event.key.keysym.sym" and "Uint8 *keystate = GetKeyState(NULL)" both worked to check if a key was down but I thought that the GetKeyState(); Function would even check when a key where HELD down

    My idea of this is that I want my player to move while holding down left or right arrow. So I did something like:

    Code:
        Uint8 *keystate = GetKeyState(NULL);
        
        if (keystate[SDLK_RIGHT])
        {
             apply_surface(x++, y, player, screen);
        }
    Can someone help me out. Just let me know how to check if a key is held down? Please!
    Last edited by DecoratorFawn82; 09-13-2013 at 10:45 AM.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Take a look at this

    The above link says that you first need to call "SDL_PumpEvents()" before calling "SDL_GetKeyState()".
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Feb 2013
    Location
    Sweden
    Posts
    171
    Thanks! That helped me figure out what to do

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. hold keyboard key
    By XxPKMNxX in forum C++ Programming
    Replies: 3
    Last Post: 07-10-2010, 12:08 PM
  2. Can large can an int hold?
    By winggx in forum C Programming
    Replies: 10
    Last Post: 04-02-2010, 04:36 AM
  3. C# - What potential does it hold?
    By dannysmith in forum C# Programming
    Replies: 14
    Last Post: 11-18-2006, 02:23 PM
  4. Texas Hold'em
    By Darryl in forum Contests Board
    Replies: 10
    Last Post: 08-21-2005, 04:51 AM
  5. Getting Hold of win API Refernce
    By Davros in forum Windows Programming
    Replies: 2
    Last Post: 08-29-2004, 04:01 PM