Page 1 of 1

OnKeyUp Not Always Working

Posted: Fri Aug 30, 2019 3:15 am
by PEB
Here's the test code:

Code: Select all

DebugPrint("Test:")

Function p_KeyDownFunc()
	DebugPrint("DOWN")
EndFunction

Function p_KeyUpFunc()
	DebugPrint("UP")
EndFunction

InstallEventHandler({OnKeyDown=p_KeyDownFunc, OnKeyUp=p_KeyUpFunc})
Now try holding down any key for a couple seconds, and then release it. You should see a long list of "DOWN" printed to the output window, with "UP" at the very end. Repeat this a few times, and it probably won't be long before you notice that "UP" was not printed at the end. However, "UP" will be printed as soon as a new event is detected---even one not specified in InstallEventHandler()---such as moving the mouse.

Re: OnKeyUp Not Always Working

Posted: Sat Aug 31, 2019 12:31 pm
by Bugala
I cant repeat the problem. How long exactly and how many times do you have to do that for it to happen, and on what machine and version?

Mine is WIndows 10, Hollywood 8, and I tried holding key down for 5 seconds down for maybe 10 times, and it always worked as expected.

Only time I get unexpected result is if i push two different keys down at same time and then release one of them. It will then result in showing "UP" but not "Down" anymore, even other key is still down. But I think this has to do with the keyboard rather than Hollywood.

I am actually thinking your case could be related to your keyboard as well, although printing UP after mouse is moved doesn't sound like a Keyboard problem anymore, since dont know how Mouse event could activate Keyboards buffer anymore, unless some signal is sent to all event places (including keyboard) to activate it, but dont know if there is such signal existing even.

Re: OnKeyUp Not Always Working

Posted: Sat Aug 31, 2019 1:44 pm
by airsoftsoftwair
@PEB: What is your test system?

Re: OnKeyUp Not Always Working

Posted: Sat Aug 31, 2019 7:57 pm
by PEB
I'm using OS4.
(It's a problem that was reported to me by someone on a different OS4 system.)

Re: OnKeyUp Not Always Working

Posted: Mon Sep 02, 2019 9:21 pm
by airsoftsoftwair
Ok, I've debugged it and it's an OS4 thing. Hollywood just forwards the key up/down events it gets from OS4 and in that case the key up event sometimes doesn't come through before the next key down press. Note that it could also be a hardware limitation. Keyboard stuff is complex on the hardware level and there are certain limitations. Not sure if this is one of them, though. You might want to ask on the Hyperion forum or so...

Re: OnKeyUp Not Always Working

Posted: Mon Sep 02, 2019 11:50 pm
by PEB
Thanks for looking into it, Andreas.

Here's a work-around, if anyone on OS4 is interested:

Code: Select all

DebugPrint("Test:")

Function p_KeyUpFunc(msg)
	Local TempKey$=msg.userdata
	If TempKey$=" " Then TempKey$="SPACE"
	If IsKeyDown(TempKey$)
		SetTimeout(1, p_KeyUpFunc, 40, TempKey$)
		Return()
	EndIf
	DebugPrint("UP")
EndFunction

Function p_KeyDownFunc(msg)
	SetTimeout(1, p_KeyUpFunc, 40, msg.key)
	DebugPrint("DOWN")
EndFunction

InstallEventHandler({OnKeyDown=p_KeyDownFunc})