ahhh help....rapid keypress detection

This is a discussion on ahhh help....rapid keypress detection within the Game Programming forums, part of the General Programming Boards category; how do i detect rapid keypresses?? If i put a variable within the if (keypress) and let it increment so ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    12

    ahhh help....rapid keypress detection

    how do i detect rapid keypresses?? If i put a variable within the if (keypress) and let it increment so that when it reach lets say 10 the thrust sound starts to kick in....once i let go even wif a single tap the thrust sound kicks in.....how do i go about this??need help fast 15 hrs to submission

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Err....uh.....is this for DirectX or what?

    If you are using the Windows GDI then its not a mystery why you are having this problem.

    If you are using DirectX, look at the following code:


    Code:
    #include "dinput.h"
    #include <objbase.h>
    
    #define INITGUID
    
    //Set objects to null
    LPDIRECTINPUT lpdi=NULL;
    IDIRECTINPUTDEVICE lpdikey=NULL;
    
    //Create DirectInput object - get interface
    if (FAILED(DirectInputCreate(main_instance,DIRECTINPUT_VERSION,&lpdi,NULL))
    { //error }
    
    //Create DirectInput device
    if (FAILED(lpdi->CreateDevice(GUID_SysKeyboard,&lpdikey,NULL))
    { //error }
    
    //Set cooperative level
    if (FAILED(lpdikey->SetCooperativeLevel(main_window_handle,DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)) {//error}
    
    //Keystate array
    typedef _DIKEYSTATE UCHAR[256];
    
    //Set data format to keyboard
    if (FAILED(lpdikey->SetDataFormat(&c_dfDIKeyboard))) {//error}
    
    //Acquire the keyboard
    if (FAILED(lpdikey->Acquire())) {//error}
    
    //Get info from the keyboard
    if (FAILED(lpdikey->GetDeviceState(sizeof(_DIKEYSTATE),(LPVOID)keystate))) {//error}
    
    //Test for key down
    if (keystate[DIK_ESCAPE] & 0x80)
    {
      //down
    }
    else
    {
      //up
    }
    
    //Could also use this macro for keydown
    #define DIKEYDOWN(data,n) (data[n] &0x80)


    This sets up the DirectInput object, Keyboard object, and shows how to test keys. It comes directly from Andre Lamothe's book, Tricks of the Windows Game Programming Gurus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (MFC, Visual C++) Keypress Detection in a dialog...
    By guitarist809 in forum Windows Programming
    Replies: 4
    Last Post: 08-31-2008, 02:13 PM
  2. Collision Detection
    By Grantyt3 in forum C++ Programming
    Replies: 3
    Last Post: 09-30-2005, 04:21 PM
  3. matrixes for collision detection
    By DavidP in forum Game Programming
    Replies: 10
    Last Post: 11-09-2002, 10:31 PM
  4. bounding box collision detection
    By DavidP in forum Game Programming
    Replies: 7
    Last Post: 07-08-2002, 12:43 AM
  5. Replies: 4
    Last Post: 05-03-2002, 10:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21