Jump to content
  • Advertisement
Sign in to follow this  
Adams555

DirectInput works for some... But not all.. (keys)

This topic is 5069 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

NOTE THAT THIS HAS BEEN RESOLVED, I WAS VERY STUPID =P For anyone that cares to know, I forgot to provide a guid. =/ I've been trying to figure out this problem for over an hour. My program copiles and runs fine. 3/4 of the keys mapped for directinput work fine as well. Here is my action mapping code.. (Probably the most likely place where the problem is.) Please take a minute to look though this. =/ Thanks.
HRESULT DirectX::SetUpActionMap(HINSTANCE hinst)
{
//sfx=new Mp3();


//number of actions
#define NUMBER_OF_ACTIONS	9L



//constants.. predefined

//constants, keyboard
#define INPUT_MOVE_FORWARD		1L
#define INPUT_MOVE_BACKWARD		2L
#define INPUT_TURN_LEFT			3L
#define INPUT_TURN_RIGHT		4L
#define INPUT_DIALOG			5L
#define INPUT_QUIT				6L
#define INPUT_MAP_PLUS			7L
#define INPUT_MAP_MINUS			8L
#define INPUT_MAP_SAVE			9L


DIACTION actions[NUMBER_OF_ACTIONS] =
{
    {INPUT_MOVE_FORWARD,	 DIKEYBOARD_UP,			0,	"Move forward", },
    {INPUT_MOVE_BACKWARD,	 DIKEYBOARD_DOWN,		0,	"Move backward", },
    {INPUT_TURN_LEFT,		 DIKEYBOARD_LEFT,		0,	"Turn left", },
    {INPUT_TURN_RIGHT,		 DIKEYBOARD_RIGHT,		0,	"Turn right", },
	{INPUT_DIALOG,			 DIKEYBOARD_SPACE,		0,	"Blah"},
	{INPUT_QUIT,			 DIKEYBOARD_ESCAPE,		0,	"Quit", },
	{INPUT_MAP_PLUS,		 DIKEYBOARD_RETURN,		0,	"Increment map"},
	{INPUT_MAP_MINUS,		 DIKEYBOARD_RSHIFT,		0,	"Enter text"},
	{INPUT_MAP_SAVE,		 DIKEYBOARD_F1,			0,	"Enter text"},
}
GUID guid;







DIACTIONFORMAT diaf;
diaf.dwSize        = sizeof(DIACTIONFORMAT);
diaf.dwActionSize  = sizeof(DIACTION);
diaf.dwDataSize    = NUMBER_OF_ACTIONS * sizeof(DWORD);
diaf.dwNumActions  = NUMBER_OF_ACTIONS;
diaf.guidActionMap = guid;
diaf.dwGenre       = DIVIRTUAL_FIGHTING_THIRDPERSON;
diaf.rgoAction     = actions;
diaf.dwBufferSize  = 16;
diaf.lAxisMin      = -100;
diaf.lAxisMax      = 100;
_tcscpy( diaf.tszActionMap, _T("DI test") );

								

	HRESULT hr;
	hr=g_lpDIDevice->BuildActionMap(&diaf,
								NULL,
								DIDBAM_DEFAULT);
							





	hr = g_lpDIDevice->SetActionMap(&diaf,
								NULL,
								DIDSAM_DEFAULT
								);

return S_OK;
}





And here is my directinput initializing code (I don't think anything is wrong here, because most of the keys work... but who knows? Something might be wrong.)
HRESULT DirectX::initDInput(HINSTANCE hinst, HWND hwnd)
{ 
	DIPROPDWORD dipdw;
    HRESULT hr; 


    DirectInput8Create(hinst, DIRECTINPUT_VERSION, 
                            IID_IDirectInput8, (void**)&g_lpDI, NULL); 

    g_lpDI->CreateDevice(GUID_SysKeyboard, &g_lpDIDevice, NULL); 

    hr = g_lpDIDevice->SetDataFormat(&c_dfDIKeyboard); 

    hr = g_lpDIDevice->SetCooperativeLevel(hwnd, 
                             DISCL_FOREGROUND | DISCL_EXCLUSIVE); 


	dipdw.diph.dwSize=sizeof(DIPROPDWORD);
	dipdw.diph.dwHeaderSize=sizeof(DIPROPHEADER);
	dipdw.diph.dwObj=0;
	dipdw.diph.dwHow=DIPH_DEVICE;
	dipdw.dwData=32;
	g_lpDIDevice->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph);

	SetUpActionMap(hinst);
    g_lpDIDevice->Acquire(); 
	
	
	return true; 
}





Note that SetUpActionMap is called from the last piece of code. And finally, here is my keyboard proccessing function. It currently displays a messagebox constantly, and I'm using that to check for what key values are pressed... But it's not working.
HRESULT DirectX::ProcessKeyboard(Camera *camera, ControlHolder* CH)
{

		DIDEVICEOBJECTDATA didod;
	    DWORD dwObjCount = 1;

	    // Poll the device for data. 
	    g_lpDIDevice->Poll(); 

		// Retrieve the data.
	    g_lpDIDevice->GetDeviceData( sizeof(didod),
                                           &didod,
                                           &dwObjCount, 0 );


		// Handle the actions regardless of what device returned them.
					char* message;
					sprintf(message,"%d",didod.uAppData);

				    MessageBox(NULL,"Failed to Create Window",message,
					MB_OK|MB_ICONERROR);
	    switch(didod.uAppData)
	    {


			case INPUT_DIALOG:
					CH->doDialog=true;
			break;

			case INPUT_MAP_SAVE:
			CH->saveMap=true;
			break;

			case INPUT_MAP_PLUS:
				CH->adjustMap=1;
				CH->changeMap=!CH->changeMap;
			break;
		
			case INPUT_MAP_MINUS:
				CH->adjustMap=-1;
				CH->changeMap=!CH->changeMap;
			break;
			
					
			case INPUT_MOVE_FORWARD:
				CH->Forward=!CH->Forward;
	            break;

			case INPUT_MOVE_BACKWARD:
				CH->Backward=!CH->Backward;
				break;

			case INPUT_TURN_RIGHT:
				CH->RRight=!CH->RRight;
	            break;

			case INPUT_TURN_LEFT:
				CH->RLeft=!CH->RLeft;
				break;
/*
			case INPUT_LOOK_UP:
				lookUp=!lookUp;
	            break;

			case INPUT_LOOK_DOWN:
				lookDown=!lookDown;
	            break;

			case INPUT_FIRST_THIRD:
				if (SwitchFirst){
					firstPerson=!firstPerson;
				}
				SwitchFirst=!SwitchFirst;
				
					break;*/

			case INPUT_QUIT:
				return E_FAIL;
				break;

		








			default:
			;		
	        break;
	    }
					//sfx->Load("SFX/Pop2.wav");
					//sfx->Play();

return S_OK;
}





I'm really stuck. Please help. Thanks, ~Adams555~

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!