Skip to main content
gamedev.net
🔒 Locked

DInput... problem detecting keydown...

Started by smitty1276 2 replies 400+ views
Original Post
smitty1276
smitty1276
Every example I''ve ever seen checks to see if a key is down like so...
bool IsKeyUp( char key ) { return (m_Keys[key] & 0x80) ? true : false; }
bool IsKeyDown( char key ) { return (m_Keys[key] & 0x80) ? false: true;  }
Of course, if GetDeviceStatus() sets the high bit of the corresponding array element, this is the correct way. I was trying to test my class in a little simple windows program, with this code...
bool bFinished = false;
	while(!bFinished)
	{
		if(Input.IsKeyDown(DIK_RETURN))
			SetWindowText(g_hWnd, "Enter pressed!");

		PeekMessage(&msg, g_hWnd, NULL, NULL, PM_REMOVE);

		if(msg.message == WM_QUIT)
			bFinished = true;
		else
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	return msg.wParam;
}
THE PROBLEM... when I run my program the window text is set to "Enter pressed!" immediately and flickers as its refreshed repeatedly thereafter, even when I''m not pushing any keys. Anyone had this problem or have any ideas why it may be happening? It is very, very frustrating...
smitty1276
smitty1276
OK, I''m an idiot... I had the function names backwards... when I switch them it doesn''t set the window title...

but NOW it won''t set the window text even if I *DO* press return.

Any idea why? I''m sure it could just be a win32 problem... am I doing something that would prevent it from setting the window''s caption? Or is it still not reading correctly?
jacklin
jacklin
Are you calling GetDeviceState() somewhere in your loop to refresh the key array every frame?
smitty1276
smitty1276
Oh my dear god, no.

I''m a complete idiot...

Thanks... you guys can now ignore this thread.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.