To practice programming menus, I'm making a simple little text adventure game system. The player is presented with multiple choices at the bottom of the screen which, when I get to it, will move them from scene to scene or have other effects. The player can move between and select the choices with keyboard or controller inputs, or they can click on them with the mouse (invisible buttons are laid over them).

I'm having a weird issue, though. If you use the keyboard/controller inputs, everything works fine. If you use the mouse, everything works fine. However, once you click on a choice with the mouse, the "confirm" keyboard/controller input breaks (though using the mouse still works fine).

In its broken state, the "confirm" input also triggers a sort of phantom mouse click - the game takes the key press and also, for some reason, treats that key press as a mouse click on the last in-game button the mouse hovered over. With the buttons' action mode set to release, this phantom mouse input is taken as the key is released, as if it were a mouse button.

I've been able to sweep the issue under the proverbial rug by having the GUI script (which is listening for keyboard/controller inputs) tell the button nodes to ignore mouse clicks when the player is using the keyboard or controller - they start acting on clicks again once the player moves the cursor over them. (This disabling behaviour is itself disabled in the project file I've provided so people can see the issue first-hand.)

That doesn't help me understand the problem, though. Has anyone else ever run into this issue? Why is the game taking key presses as mouse clicks?

Normal behaviour:

Broken behaviour, using keyboard/controller to make a choice after having made one with a mouse click:

Very much open to critiques of my ham-handed noob code, by the way, if anyone has any suggestions for how it can be improved.

Disregard this, I don't actually think you can remap the mouse nor is it the cause :S ~~At a glance you are only capturing "ui_accept", so I would guess have both mouse clicks and keyboard presses bound to this event.

You can modify/add keymaps in Project Settings > Input Map and create a new entry (called left_mb for example) and split then handle them seperately in the code:

	if Input.is_action_just_pressed("ui_accept"):
		choice_confirmed(choice_hilight)

	if Input.is_action_just_pressed("left_mb"):
		choice_confirmed(choice_hilight)~~

@Bimbam said: At a glance you are only capturing "ui_accept", so I would guess have both mouse clicks and keyboard presses bound to this event.

Thanks for the suggestion, but not the case. I just tried it again with a new input but the result is the same.

@Megalomaniak said: Focus follows mouse probably.

Please explain. I've not come across focus before in Godot. Why should this make another input behave like a mouse click?

https://en.wikipedia.org/wiki/Focus_(computing)

https://docs.godotengine.org/en/stable/classes/class_control.html

Godot sends input events to the scene's root node first, by calling Node.input. Node.input forwards the event down the node tree to the nodes under the mouse cursor, or on keyboard focus. To do so, it calls MainLoop.input_event. Call accept_event so no other node receives the event. Once you accepted an input, it becomes handled so Node.unhandled_input will not process it.

Only one Control node can be in keyboard focus. Only the node in focus will receive keyboard events. To get the focus, call grab_focus. Control nodes lose focus when another node grabs it, or if you hide the node in focus.

Sets(sic) mouse_filter to MOUSE_FILTER_IGNORE to tell a Control node to ignore mouse or touch events. You'll need it if you place an icon on top of a button.

2 years later