Jump to content
  • Advertisement
Sign in to follow this  
Toastmastern

C++ DirectInput release key not detected

Recommended Posts

So have been struggeling with this issue now for 20 hours or so. I'm using DirectInput, I know it's not the best but I have tried other approaches aswell which yields me the same results. What is happening is that I'm orbiting around a sphere with my up and down cursor buttons. Nothing to complicated really. What my issue is however is that when I press the key and hold it for a while(atleast this seems to be when the issue occurs, I have seen it at other times aswell but not as common) the keystate I get from DirectInput doesn't recognize that I have released the key. I can see from my debugging that I get a new keyboardState, and I can also see that from that keyboardState the key is still down, even tho I don't press it. This lag, delay or freeze or whatever one wants to call it can be up to several seconds. Here is a hastebin that includes the code in question:

https://hastebin.com/ayucajobaw.cpp

Any kind of ideas what my issue could be, or pointers for me what to google, cause I'm really running out of ideas here

Best Regards
Toastmastern

Share this post


Link to post
Share on other sites
Advertisement

Are you pressing other keys at the same time? There's a lot of keyboards where some key combinations do not register (try two cursor keys with space for example).

If that is the problem it's a hardware issue and you really can't do anything about it but use different keys. Custom key mapping is always recommended.

Share this post


Link to post
Share on other sites
19 hours ago, Endurion said:

Are you pressing other keys at the same time? There's a lot of keyboards where some key combinations do not register (try two cursor keys with space for example).

If that is the problem it's a hardware issue and you really can't do anything about it but use different keys. Custom key mapping is always recommended.

Yea that isn't the issue. I rebuilt the input system to work with Raw Input instead to try and improve the system overall. What I've noticed now that it is something with the key repeat function. This is the code I'm testing on right now
 

		case WM_INPUT:
		{
			char buffer[sizeof(RAWINPUT)] = {};
			UINT size = sizeof(RAWINPUT);
			GetRawInputData(reinterpret_cast<HRAWINPUT>(lparam), RID_INPUT, buffer, &size, sizeof(RAWINPUTHEADER));

			// extract keyboard raw input data
			RAWINPUT* rawInput = reinterpret_cast<RAWINPUT*>(buffer);
			if (rawInput->header.dwType == RIM_TYPEKEYBOARD)
			{
				const RAWKEYBOARD& rawKB = rawInput->data.keyboard;
				// do something with the data here

				UINT virtualKey = rawKB.VKey;

				switch (virtualKey)
				{
				case Keyboard::W:
					if (rawInput->data.keyboard.Flags == RI_KEY_MAKE)
					{
						printf("W PRESSED!\r\n");
					}
					if (rawInput->data.keyboard.Flags == RI_KEY_BREAK)
					{
						printf("W RELEASED!\r\n");

					}					
					break;
				}
			}
		}

This is so basic code that there is nothing in my engine that can #*@! it up ^^ What happens that when I hold down the W key and then releases the W RELEASED! Text isn't printed until sometimes seconds has passed and W PRESSED! has printed like 20 more times. 
I mean I can handle it logically if just the W release is actually happening when the key is released and not until some que of W PRESSED is printed :S 

//Toastmastern

Share this post


Link to post
Share on other sites

Are you processing the whole of the windows message queue on each game loop?

Share this post


Link to post
Share on other sites
Posted (edited)

Yes, it sounds like you're only processing one Get/PeekMessage() per game loop, this is incorrect.  You need to loop until they're all processed in general.  I use raw input and I instantly get the message when the key is released.

Edit:
Make a new win32 project, have it load a blank window and just process keyboard input.  See if you can reproduce the issue then put the code up on a site where it's only maybe 200 lines long so we can look it over for you.

Edited by CrazyCdn

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
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!