IsKeyDown hangup

Report any Hollywood bugs here
Post Reply
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

IsKeyDown hangup

Post by amyren »

This strange behaviour happens when pressing the shift key simultaniously with another key.
I just tested on two different windows pc's, just to make sure it wasnt my laptop that was the problem.
On my laptop it is very easy to reproduce it, on the desktop pc I need to give it some more tries to reproduce the problem.

It should be possible to reproduce it using the script below
What happens is that when pressing and releasing the "a" or "b" key at the exact same as pressing down the left or right shift key, then IsKeyDown will still be true until the key is pressed again.

Code: Select all

StartTimer(1)
Repeat
	t1 = GetTimer(1)
	If t1 > 200
		If IsKeyDown("a") Then NPrint("a pressed")	
		If IsKeyDown("b") Then NPrint("b pressed")	
		ResetTimer(1)
	EndIf
Forever
Edit: It seems that it can be avoided by using ResetKeyStates(), but I still feel this might be a bug?
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: IsKeyDown hangup

Post by airsoftsoftwair »

For multi-key sequences you should use raw keys instead, i.e.

Code: Select all

StartTimer(1)
Repeat
	t1 = GetTimer(1)
	If t1 > 200
		If IsKeyDown("A", True) Then NPrint("a pressed")	
		If IsKeyDown("B", True) Then NPrint("b pressed")	
		ResetTimer(1)
	EndIf
Forever
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Re: IsKeyDown hangup

Post by amyren »

Thanks, using raw keys will resolve this for the script I'm working on.

But why it does hang up when rawkeys are not used and certain mulitple keys are pressed, that remains a mystery to me.
With this in mind, I feel that the most safe way to use IsKeyDown is to always use the raw keys option, unless I specificly needs to separate a lowerstring from upperstring characters.
Or are there any other downsides of using rawkey here?

I also did a test to check if this happens with other that alphabetical letters, and I did manage to get the same issuse by using IsKeyDown("SPACE") and then hitting Space and Alt toghether. Also when using "LSHIFT" and hitting both shift keys.
But it seem to happen less frequent with these keys, than in my previous example.

Code: Select all

StartTimer(1)
Repeat
	t1 = GetTimer(1)
	If t1 > 200
		If IsKeyDown("SPACE") Then NPrint("SPACE pressed")	
		If IsKeyDown("LSHIFt") Then NPrint("LSHIFT pressed")	
		ResetTimer(1)
	EndIf
Forever
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: IsKeyDown hangup

Post by airsoftsoftwair »

amyren wrote: Sat Sep 19, 2020 7:35 pm But why it does hang up when rawkeys are not used and certain mulitple keys are pressed, that remains a mystery to me.
IsKeyDown() is pretty much broken by design because it also allows you to examine combinations of keys, e.g. you could also check if "!" is down although that is not a key but a combination of keys. Thus, in its default (legacy) mode it is not really safe to use in combination with modifier keys like shift or alt. As soon as modifier keys are involved you should use IsKeyDown() in rawkey mode so that it knows that you're looking for rawkey states and not for characters generated by pressing a combination of keys.
Post Reply