Skip to main content
gamedev.net
🔒 Locked

DirectInput Keyboard Errors

Started by chessgeek Dec 28, 2008 at 7:41 PM 1 replies 950+ views
Original Post
chessgeek
chessgeek
I'm making an expandable engine that keeps giving me errors when I input a key code into it.

void GetKeys(UCHAR* KeyState)
{
	dinkeyboard->Acquire();
	
	dinkeyboard->GetDeviceState(sizeof(UCHAR[256]), (LPVOID)keystate);

	for(int Index = 0; Index < 256; Index++)
		*(KeyState + Index) &= 0x80;

	return;
}

	if (GetKeys(DIK_ESCAPE) & 0x80)
	{
		PostMessage(hWnd, WM_DESTROY, 0, 0);
	}


those are obviously in separate .cpp files. However it keeps giving me an error that states: error C2664: 'GetKeys' : cannot convert parameter 1 from 'int' to 'UCHAR *'
Evil Steve
Evil Steve
1. Your GetKeys function takes a keyboard state as a parameter, but you're passing in a single character.
2. What is your keystate variable declared as? It has different case from KeyState, and is a different variable.
3. PostMessage() is not the correct way to destroy your window for a large number of reasons. The best case is that your code crashes on your machine. The worst case is that your code crashes on some future version of Windows which doesn't expect you to be breaking things in that way. The correct thing to do is to call DestroyWindow().
4. As rip-off said, DirectInput for keyboard input is a brilliant way of wasting hours of your life, infuriating users, and stopping your app from running correctly on any keyboard layout apart from the one you happen to be using.

Topic Locked

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

Sign in to reply to this topic.