OnKeyUp Not Always Working

Report any Hollywood bugs here
Post Reply
PEB
Posts: 246
Joined: Sun Feb 21, 2010 1:28 am

OnKeyUp Not Always Working

Post by PEB » Fri Aug 30, 2019 3:15 am

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.

Bugala
Posts: 788
Joined: Sun Feb 14, 2010 7:11 pm

Re: OnKeyUp Not Always Working

Post by Bugala » Sat Aug 31, 2019 12:31 pm

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.

User avatar
airsoftsoftwair
Posts: 3121
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: OnKeyUp Not Always Working

Post by airsoftsoftwair » Sat Aug 31, 2019 1:44 pm

@PEB: What is your test system?

PEB
Posts: 246
Joined: Sun Feb 21, 2010 1:28 am

Re: OnKeyUp Not Always Working

Post by PEB » Sat Aug 31, 2019 7:57 pm

I'm using OS4.
(It's a problem that was reported to me by someone on a different OS4 system.)

User avatar
airsoftsoftwair
Posts: 3121
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: OnKeyUp Not Always Working

Post by airsoftsoftwair » Mon Sep 02, 2019 9:21 pm

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...

PEB
Posts: 246
Joined: Sun Feb 21, 2010 1:28 am

Re: OnKeyUp Not Always Working

Post by PEB » Mon Sep 02, 2019 11:50 pm

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})

Post Reply