Input behavior multiple buttons pressed (SOLVED)

When you press multiple buttons on keyboard and process the input information, there is a reproduceable small bug. it happens when you press 2 movement keys and the space key simulatnious.

I will explain:
If you press right key + down key + space key simultanious the “space key=>fire” will not trigger in “on_input”
if you press left key + down key + space key simultanious the “space key => fire” will trigger in “on_input”

the setup to reproduce:
input-behavior

the code to reproduce:

function on_input(self, action_id, action)

    if action_id == hash("fire") then 
		if (os.clock() - self.lastfire > 0.13) then
		self.firing = true
		self.lastfire=os.clock()	
		end
	end
	  
	  if action_id == hash("up") then
        self.input.y = 1  
        self.moving = true
    elseif action_id == hash("down") then
        self.input.y = -1
        self.moving = true
    elseif action_id == hash("left") then
        self.input.x = -1
        self.moving = true
    elseif action_id == hash("right") then
        self.input.x = 1
        self.moving = true
    end

end

Can you put print() statements in the code at each condition to double check what arrives in on_input()?

I’m 99% sure that’s your keyboard, not Defold. On my brother’s keyboard it’s left + up + space that doesn’t work. Try it in another program and see if it works there.

3 Likes

ross.grams you are right. very interesting observation:
KEY_A for fire, allows everything simultanious (up/left/fire…)
KEY_SPACE for fire shows the problem with some combinations not triggering the "fire"
KEY_Q for fire shows the problem with some combinations not triggerting the “fire”

So the keyboard process is somehow involved.
@sicher I did print statements. and the “fire” action never arrives in the on_input
when right key + down key + space key are simultanious pressed
but as stated above. the observation is connected to the type of key which is mapped to action "fire"
I am using: Win10 , Acer aspire v15 notebook. In other games i never felt a limit of simultanious pressed buttons.

3 Likes

Yeah, it just depends how your specific keyboard is wired. I think most keyboards only guarantee that any 2 or any 3 keys can be pressed at once (besides modifier keys presumably). That’s why you may hear fuss about “mechanical keyboards”, and “n-key rollover” for gaming. A real n-key rollover keyboard has every key separated, so you never get conflicts. You can find a little visualizer to look for conflicts here, and an explanation for why it happens.