XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

DirectInput key always pressed?

Last post 03-28-2008 2:39 PM by Alexhbg. 1 replies.
  • 01-30-2008 3:01 AM

    DirectInput key always pressed?

    Hi I've been making an input engine for my game using DirectInput8 - got most of the code from a book.  Problem is that I seem to be getting the same mouse information regardless of whether a button is pressed or not.

    Here is my initialization:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    int res = DirectInput8Create(::GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_di, NULL);

    if (FAILED(res)){
      g_pLogger->error("Could not create Input Device");
      return;
    }
    res = m_di->CreateDevice(GUID_SysMouse, &m_mouse, NULL);
    if (FAILED(res)){
      g_pLogger->error("Could not create mouse interface");
      return;
    }
    if (FAILED(m_mouse->SetDataFormat(&c_dfDIMouse))){
      g_pLogger->error("Could not set data format for mouse");
      return;
    }
    if (FAILED(m_mouse->SetCooperativeLevel(m_hWnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))){
      g_pLogger->error("Could not set coop level for mouse");
      return;
    }
    if (FAILED(m_mouse->Acquire())){
      g_pLogger->error("Could not acquire mouse");
      return;
    }


    Here is the updating:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    while (true){
      m_mouse->Poll();
      if (SUCCEEDED(res = m_mouse->GetDeviceState(sizeof(DIMOUSESTATE), &m_mouseState)))
        break;

      if (res != DIERR_INPUTLOST && res != DIERR_NOTACQUIRED){
        g_pLogger->error("Could not get mouse state???");
        return;
      }

      if (FAILED(m_mouse->Acquire())){
        g_pLogger->error("Could not reacquire mouse!!!!");
        return;
      }
    }


    Now if i check each of the four .rgbButtons values I get
    rgbButtons = {205,205,410,615}
    these values don't change if I click any of the buttons...
    this is odd - I came about it by finding that my button was always pressed (Coz 205 & 0x80  is not 0)

    any help would be much appreciated !!
    I reli hope its something stupid that I've done
  • 03-28-2008 2:39 PM In reply to

    Re: DirectInput key always pressed?

    If you lose the mouse device, you exit out of the function.. this means your re-acquire code is never called (that comes after).

    Gamertag: Prey074
    Website: homebrewgames.co.uk
Page 1 of 1 (2 items) Previous Next