dinput mouse problem

Started by
5 comments, last by neonoblivion 20 years, 7 months ago
I''m getting all zero''s for my mouse data. this is my init code.

GIB_API int ginit(float r, float g, float b){
	//dsound

 	if(DirectSoundCreate(NULL,&lpds,NULL)!=DS_OK)
      return (1);
	
	if(FAILED(lpds->SetCooperativeLevel(hwnd,DSSCL_NORMAL)))
      return (1);

	if (DirectInputCreate(hin,DIRECTINPUT_VERSION,&lpdi,NULL)!=DI_OK)
      return (1);
   //keyboard

	if (lpdi->CreateDevice(GUID_SysKeyboard, &lpdikey, NULL)!=DI_OK)
      return (1);

	if (lpdikey->SetCooperativeLevel(hwnd, 
                DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK)
      return (1);

	if (lpdikey->SetDataFormat(&c_dfDIKeyboard)!=DI_OK)
      return (1);

   if (lpdikey->Acquire()!=DI_OK)
      return (1);
   ///

   ///

   //mouse

   ///

   ///

   if (lpdi->CreateDevice(GUID_SysMouse, &lpdimouse, NULL)!=DI_OK)
      return (1);

	if (lpdimouse->SetCooperativeLevel(hwnd,
                DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK)
      return (1);

	if (lpdimouse->SetDataFormat(&c_dfDIMouse)!=DI_OK)
      return (1);

   if (lpdimouse->Acquire()!=DI_OK)
      return (1);
   ///

   ///

   //end mouse

   ///

   ///


	glShadeModel(GL_SMOOTH);
	glClearColor(r, g, b, 0.5f);
   glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST);				
	glDepthFunc(GL_LEQUAL);
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	return(0);
}
this is the update code.

GIB_API void startinput(){
   if(lpdikey->GetDeviceState(sizeof(char)*256,keystate)==DIERR_INPUTLOST){
      lpdikey->Acquire();
      lpdikey->GetDeviceState(sizeof(char)*256,keystate);
   }
   if(lpdimouse->GetDeviceState(sizeof(DIMOUSESTATE),(LPVOID)&mousestate)==DIERR_INPUTLOST){
      lpdimouse->Acquire();
      lpdimouse->GetDeviceState(sizeof(DIMOUSESTATE),(LPVOID)&mousestate);
   }
   ShowCursor(FALSE);
}
the structure i get back has only 0''s for the xyz. I''ve never done this before so it''s probably somthing stupid, please help, Klaus.
Advertisement
I think your problem is as follows:

You need to create a mouse device as well as a keyboard device:

//Create the mouse device object
if(FAILED(m_pDirectInput->CreateDevice(GUID_SysMouse, &m_pMouse, NULL)))
{
CleanUpDirectInput();
//LogError("
  • Unable to create DirectInput mouse device interface.");
    return false;
    }

    Also, I think you should aquire (both keyboard and mouse) after the creation (and only once), not in the update code.
  • Sorry, I didnt see all your code (Im new here) - you do create a mouse device as well. Please ignore my reply!!!!
    np thx for trying
    Stupid question: your init function return 0 or 1 ?
    Also why you assume in function that checks input that after an Aquire the GetDeviceState will not fail again? Check for that too(use a while or just a single if and retry next frame).
    Also, cooperative level should not be NONEXCLUSIVE | FOREGROUND ?
    Petru.
    hey Petru, my init function returns 0. i assume that the GetDeviceState will not fail because, the tutorials I''ve read say that the reason that it would fail is that the hold the program has on the mouse has been lost. sorry i didn''t say i call startinput() every frame. FOREGROUND just means that the prog only takes input when in focus rather than BACKGROUND which is always, i think ;b.
    Always check return codes. It is very likely that if you''re getting all 0s, the function is not returning success. It may be that you need check for DIERR_NOTACQUIRED in addition to DIERR_INPUTLOST. I think they mean about the same. But check what error you''re getting and then you can fix it.

    This topic is closed to new replies.

    Advertisement