There's an input bug with both shift and keypad keys (SOLVED)

Here’s a simple example to illustrate this bug.

local hash_shift = hash("shift")
local hash_action_a = hash("action_a")
local hash_action_kp_4 = hash("action_kp_4")

function init(self)
	msg.post(".", "acquire_input_focus")
end

function on_input(self, action_id, action)
	if action_id == hash_shift then
		if action.pressed then
			self.shift = true
			print("shift pressed")
		elseif action.released then
			self.shift = false
			print("shift released")
		end
	elseif action_id == hash_action_a and action.pressed then
		if self.shift then
			print("shift action a")
		else
			print("action a")
		end
	elseif action_id == hash_action_kp_4 and action.pressed then
		if self.shift then
			print("shift action kp4")
		else
			print("action kp4")
		end
	end
end

If I type “a” on the keyboard, and then hold down shift and type “a”, it looks like this:

DEBUG:SCRIPT: action a
DEBUG:SCRIPT: shift pressed
DEBUG:SCRIPT: shift action a
DEBUG:SCRIPT: shift released

However, if I type 4 on the numeric keyboard, and then hold down shift to do the same - you’ll see this:

DEBUG:SCRIPT: action kp4
DEBUG:SCRIPT: shift pressed
DEBUG:SCRIPT: shift released
DEBUG:SCRIPT: action kp4
DEBUG:SCRIPT: shift pressed
DEBUG:SCRIPT: shift released

It sends me a shift released action when I hit kp4, if I’m holding down shift - then another pressed action immediately afterwards.

Weird. On macOS?

No, sorry - this is on Windows.

Does the shift-released event happen exactly when you press kp4? I’m wondering if it’s just “keyboard ghosting”.

2 Likes

This is exactly what’s happening. As long as I hold down shift, nothing happens. As soon as I hit kp4 I get the released, kp4, and pressed events.

To figure out whether this is an issue with my keyboard - or I guess, windows handling of the keyboard, I went to https://w3c.github.io/uievents/tools/key-event-viewer.html
And yes, it seems that if I hold down shift, press anything on the numeric keyboard, I do get the released event just before the kp4 event.

So - fortunately for you all, it’s not an issue for Defold. Unfortunately for me, I need to figure out how to deal with this.

2 Likes

Maybe a key rollover issue?