No mouse pressed/released in on_input

I am testing Defold. I am trying to recognize mouse clicks. I have a game object with the following script. I only get mouse position, no pressed or released. Also, I can get key clicks (I removed that for this test).

– t_to_str converts a LUA table to a string.
function t_to_str(t)
s = ""
for k, v in pairs(t) do
s = s … tostring(k) … “:” … tostring(v) … " "
end
return s
end

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

function final(self)
msg.post(".", “release_input_focus”)
end

function on_input(self, action_id, action)
if action.pressed then
print("on_input: pressed " … t_to_str(action))
elseif action.released then
print("on_input: released " … t_to_str(action))
else
print("on_input: weird " … t_to_str(action))
end
end

Have you added a mouse button trigger to your input file (MOUSE_BUTTON_LEFT or MOUSE_BUTTON_1)?

Yes. I have tried both.

Side note/tip: You can use the “pprint(table)” to print a table. E.g.

function on_input(self, action_id, action)
    print(action_id)
    pprint(action)
end

Thanks. That will be helpful.

I figured it out (sort of). In game_input.binding I had touch set to generate the same action. When I removed this everything started to work.

Ah, are you using multi-touch? If not, then you don’t need to set any touch trigger at all.

I was intending to eventually use multi-touch. But that was probably a misunderstanding. If my test only needs single touch I just need to handle the mouse click and that will also handle single touch?

Correct. The input documentation mentions “Currently, MOUSE_BUTTON_LEFT (or MOUSE_BUTTON_1) input actions are sent for single touch inputs as well.”

Maybe we should clarify that you have to bind MOUSE_BUTTON_LEFT/1 to get touch events @sicher?

2 Likes

Yes. I didn’t understand.

But why would my setting both interfere with mouse clicks (pressed and released)?

Good question. I know for a fact that if you have multi-touch and mouse left button bound to the same trigger action then it messes up single touch. @Ragnar_Svensson maybe knows more?

That should absolutely not happen, I think multi-touch is buggy.

Thanks. We have two issues related to multi-touch: DEF-1726 and DEF-2024. We should probably give these a bit higher priority in the next planning meeting @jakob.pogulis?

Though I agree with you, the backlog looks kind of packed for the next sprints. Maybe @Sara (or @saracederberg?) could give a better answer in case we could move something around.

Thanks for all of your help.

Is this already fixed?
I cannot bind mouse and multitouch to the same action id name “touch”. If I do, I only get multitouch input on mobile, and nothing on PC. But if I set separated IDs, trying to find a hack like “touch” and “mtouch”, then I get fine input on PC, but now I got BOTH “touch” and “mtouch” on mobile… so I’ll need a 2nd hack to ignore “touch” on mobile platform :roll_eyes:
Clipboard01__fru

Also, wondering what would happen if the Desktop PC has multitouch, I can’t use Sys_info to assume the support of multi-touch or not…

We don’t support touch on desktop I’m afraid.

Also, tested that is not supported on HTML 5.
Would be nice to have multi-touch on HTML5, the full screen mode makes the game looks like a native app when opening in a mobile browser, is perfect for sending a game demo to people with a simple web link.

Yes, this was discussed internally not too long ago. I hope that we can find some time to fix this soon.

1 Like