Jump to content
  • Advertisement
Sign in to follow this  
eltharynd

directinput problem

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

so I'm developing a game engine...

but now a have a strange problem with input....

here's the function that gets the key states from the keyboard device: 

void Controls::GetKeyboard()
{
	if(FAILED(mKeyboardDevice->GetDeviceState(sizeof(mKeyboardKeys), (LPVOID)&mKeyboardKeys)))
		mKeyboardDevice->Acquire();

	
	if(KEYDOWN(mKeyboardKeys,DIK_LEFT) && KEYDOWN(mPrevKeyboardKeys, DIK_LEFT))
		mapKeys["LEFT"]=K_HLD;
	else if(KEYDOWN(mKeyboardKeys,DIK_LEFT) && !KEYDOWN(mPrevKeyboardKeys, DIK_LEFT))
		mapKeys["LEFT"]=K_PRS;
	else if(!KEYDOWN(!mKeyboardKeys,DIK_LEFT) && KEYDOWN(mPrevKeyboardKeys, DIK_LEFT))
		mapKeys["LEFT"]=K_RLS;
	else
		mapKeys["LEFT"]=K_NO;


	if(KEYDOWN(mKeyboardKeys,DIK_RIGHT) && KEYDOWN(mPrevKeyboardKeys, DIK_RIGHT))
		mapKeys["RIGHT"]=K_HLD;
	else if(KEYDOWN(mKeyboardKeys,DIK_RIGHT) && !KEYDOWN(mPrevKeyboardKeys, DIK_RIGHT))
		mapKeys["RIGHT"]=K_PRS;
	else if(!KEYDOWN(!mKeyboardKeys,DIK_RIGHT) && KEYDOWN(mPrevKeyboardKeys, DIK_RIGHT))
		mapKeys["RIGHT"]=K_RLS;
	else
		mapKeys["RIGHT"]=K_NO;


	if(KEYDOWN(mKeyboardKeys,DIK_UP) && KEYDOWN(mPrevKeyboardKeys, DIK_UP))
		mapKeys["UP"]=K_HLD;
	else if(KEYDOWN(mKeyboardKeys,DIK_UP) && !KEYDOWN(mPrevKeyboardKeys, DIK_UP))
		mapKeys["UP"]=K_PRS;
	else if(!KEYDOWN(!mKeyboardKeys,DIK_UP) && KEYDOWN(mPrevKeyboardKeys, DIK_UP))
		mapKeys["UP"]=K_RLS;
	else
		mapKeys["UP"]=K_NO;


	if(KEYDOWN(mKeyboardKeys,DIK_DOWN) && KEYDOWN(mPrevKeyboardKeys, DIK_DOWN))
		mapKeys["DOWN"]=K_HLD;
	else if(KEYDOWN(mKeyboardKeys,DIK_DOWN) && !KEYDOWN(mPrevKeyboardKeys, DIK_DOWN))
		mapKeys["DOWN"]=K_PRS;
	else if(!KEYDOWN(!mKeyboardKeys,DIK_DOWN) && KEYDOWN(mPrevKeyboardKeys, DIK_DOWN))
		mapKeys["DOWN"]=K_RLS;
	else
		mapKeys["DOWN"]=K_NO;


	if(KEYDOWN(mKeyboardKeys,DIK_A) && KEYDOWN(mPrevKeyboardKeys, DIK_A))
		mapKeys["A"]=K_HLD;
	else if(KEYDOWN(mKeyboardKeys,DIK_A) && !KEYDOWN(mPrevKeyboardKeys, DIK_A))
		mapKeys["A"]=K_PRS;
	else if(!KEYDOWN(!mKeyboardKeys,DIK_A) && KEYDOWN(mPrevKeyboardKeys, DIK_A))
		mapKeys["A"]=K_RLS;
	else
		mapKeys["A"]=K_NO;


	if(KEYDOWN(mKeyboardKeys,DIK_D) && KEYDOWN(mPrevKeyboardKeys, DIK_D))
		mapKeys["D"]=K_HLD;
	else if(KEYDOWN(mKeyboardKeys,DIK_D) && !KEYDOWN(mPrevKeyboardKeys, DIK_D))
		mapKeys["D"]=K_PRS;
	else if(!KEYDOWN(!mKeyboardKeys,DIK_D) && KEYDOWN(mPrevKeyboardKeys, DIK_D))
		mapKeys["D"]=K_RLS;
	else
		mapKeys["D"]=K_NO;


	if(KEYDOWN(mKeyboardKeys,DIK_W) && KEYDOWN(mPrevKeyboardKeys, DIK_W))
		mapKeys["W"]=K_HLD;
	else if(KEYDOWN(mKeyboardKeys,DIK_W) && !KEYDOWN(mPrevKeyboardKeys, DIK_W))
		mapKeys["W"]=K_PRS;
	else if(!KEYDOWN(!mKeyboardKeys,DIK_W) && KEYDOWN(mPrevKeyboardKeys, DIK_W))
		mapKeys["W"]=K_RLS;
	else
		mapKeys["W"]=K_NO;

	if(KEYDOWN(mKeyboardKeys,DIK_S) && KEYDOWN(mPrevKeyboardKeys, DIK_S))
		mapKeys["S"]=K_HLD;
	else if(KEYDOWN(mKeyboardKeys,DIK_S) && !KEYDOWN(mPrevKeyboardKeys, DIK_S))
		mapKeys["S"]=K_PRS;
	else if(!KEYDOWN(!mKeyboardKeys,DIK_S) && KEYDOWN(mPrevKeyboardKeys, DIK_S))
		mapKeys["S"]=K_RLS;
	else
		mapKeys["S"]=K_NO;

	memcpy(mPrevKeyboardKeys, mKeyboardKeys, sizeof(mKeyboardKeys));

}

so i wrote a little code that translates two sprites, one controlled by WASD and the other by UP DOWN LEFT RIGHT keys...

everything goes fine but something strange happens:

 

i can't press A, S, DOWN, RIGHT at the same time....

 

if i hold A+S  --> R works but D doesn't, if i hold D+R none of them works

if i hold R+D  --> A works but S doesn't, if i hold A+S none of them works

 

it cannot be the rest of the code cause the sprites are translated separately for each direction (so no conflicts)...

 

what i was thinking is that there might be some kind of Windows-based or DirectInput-based restriction...

any ideas anyone?

 

 

 

EDIT: also if i press ASDownRight at the same time nothing works

Edited by eltharynd

Share this post


Link to post
Share on other sites
Advertisement

For text input to GUI you can use WM_CHAR in WinProc. For controlling a character (WASD) you can use GetAsyncKeyState.

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!