Topic was automatically imported from the old Question2Answer platform.
Asked By
blurrred
If I press a button on Android with the virtual keyboard open, the keyboard closes. I would like to prevent this behavior for certain buttons. Is this possible?
This is the best I could figure out on my own. Attach this script to the button you want to click without lowering the mobile keyboard.
extends Button
func _input(event):
if event is InputEventMouseButton && \
event.button_index == MOUSE_BUTTON_LEFT && \
event.pressed == true && \
point_in_square(event.position, global_position, size) == true:
get_viewport().set_input_as_handled()
emit_signal('pressed') # since we set the input as handled before it reaches the GUI (button), we must manually emit the pressed signal.
func point_in_square(inner, outer, size):
if inner.x > outer.x && \
inner.y > outer.y && \
inner.x < outer.x + size.x && \
inner.y < outer.y + size.y:
return true
return false
We check if the event is a mouse button because Godot actually registers button clicks on phones as mouse button clicks. Don’t believe me? Try printing the event from _input(event) on a Button and see that it gives you both an InputEventScreenTouch (which does not trigger the button) and an InputEventMouseButton, which does.