Hi,
I’ve got a problem with Input.GetKeyDown and Input.GetKeyUp in WebGL
My game has two phases, a question phase and play phase. A game goes Question Phase → Play Phase → Question Phase → Play Phase and so on.
In the question phase the user answers question in an embedded html page. Because of this, in the question phase we set - WebGLInput.captureAllKeyboardInput to false. And when the question phase enters we enable it so that the user can move around in their play phase.
The problem we have is when a user is holding down a key when their play phase ends and they go into question phase. They then release the input. Then they go back into the player, and press the same key down again. We don’t receive the key down event
Here is a simplified time line:
// User presses 'W'
// Input.GetKeyDown('W') received
// Question Phase starts
WebGLInput.captureAllKeyboardInput = false;
// User releases 'W'
// Input.GetKeyUp('W') not received
// Question Phase ends
WebGLInput.captureAllKeyboardInput = true;
// User presses 'W'
// Input.GetKeyDown('W') not received
// User releases 'W'
// Input.GetKeyUp('W') received
// User presses 'W'
// Input.GetKeyDown('W') received
Looking at the documention for GetKeyDown it says:
" It will not return true until the user has released the key and pressed it again."
So our problem is that unity doesn’t think the user has released the key. Because it happens while Unity is ignoring key events. So we don’t get the new KeyDown event.
Is there a way that I can trigger an Input.GetKeyUp event from the code?