Jump to content
  • Advertisement
Sign in to follow this  

Direct Input test failed

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

Hello, I am new to DirectX and I was trying to run some test using DirectInput. I copyed the following code almos exactly form "Core Techniques and Algorithms in Game Programming" just to see how it works all I am trying to do is to output 1 when "W" is pressed but It doesn't work. I tryed a lot of variations but I can't find the problem. Here is the code
int main()
        BYTE diks[256];
        HWND hWnd = GetConsoleHwnd();

        ZeroMemory(diks, sizeof(diks));

        HRESULT hr= DirectInput8Create(GetModuleHandle(NULL),DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI, NULL);

        hr= g_pDI->CreateDevice(GUID_SysKeyboard, &g_pKeyboard, NULL);
        hr= g_pKeyboard->SetDataFormat(&c_dfDIKeyboard);
        hr= g_pKeyboard->SetCooperativeLevel(hWnd,DISCL_FOREGROUND | DISCL_EXCLUSIVE);
		hr= g_pKeyboard->Acquire();
		hr= g_pKeyboard ->GetDeviceState(sizeof(diks),diks);
			hr= g_pKeyboard->Acquire();
				hr= g_pKeyboard->Acquire();

			hr= g_pKeyboard ->GetDeviceState(sizeof(diks),(LPVOID)&diks);
		cout<<((diks[DIK_W] & 0x80)!=0);
	if(g_pKeyboard) g_pKeyboard->Unacquire();

The only output I am getting is 0's. Thanks a lot for your Help!

Share this post

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

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!