Jump to content
  • Advertisement
Sign in to follow this  
Providence

bit of a problem here

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

I simply cannot figure out what's wrong here. The situation is, when I press the "d" key, the program closes. This is great. I want it to close when I press any of the wasd keys. But it doesn't close when I press "w", "a", or "s". man.moving is an int.
int ReadKeyboard() {

	BYTE buffer[256];
	ZeroMemory(buffer,256);

	HRESULT hr = keyboard->GetDeviceState(sizeof(buffer),buffer);

	if (FAILED(hr)) {
		if (hr == DIERR_NOTACQUIRED) return 0x13;
	}

	// important index 
	// 0x01 escape
	// 0x11 w
	// 0x1e a
	// 0x1f s
	// 0x20 d
	// 0xc8 up
	// 0xcb left
	// 0xd0 down
	// 0xcd right

	if (buffer[0x11])  {		// w 
		man.moving |= 0x01;
	}
	else {
		man.moving &= 0x01;
	}

	if (buffer[0x1e]) {			// a
		man.moving |= 0x02;
	}	
	else {
		man.moving &= 0x02;
	}

	if (buffer[0x1f]) {			// s
		man.moving |= 0x04;
	}
	else {
		man.moving &= 0x04;
	}

	if (buffer[0x20]) {			// d
		man.moving |= 0x08;
	}
	else {
		man.moving &= 0x08;
	}


	return man.moving;
}
As you can see I want it to set/unset flags based on which keys are down. If man.moving is true, the program exits. It only exits if I press d though. in WinMain():
if (int errorc = ReadKeyboard()) return errorc; 

...and I just realized my error handling wasn't releasing any memory, just rather abruptly exiting the program.

Share this post


Link to post
Share on other sites
Advertisement
Because my ultimate goal is to use the information, not exit the program. However, when I tried to use the information in the man.moving variable only the "d" seemed to have worked. So I came back to this function and looked at it, to see if the problem lies in it, and I believe that it does.

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.

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!