+1 vote

Hello,

How can I enable / disable input for entire application from GDScript?

The desired effect is that all input devices (mouse, keyboard, controllers, touches, etc) will be enabled / disabled for the entire application from GDScript.

Best regards,
Radu

[Later edit]: Using 2.1.4 official stable
[Update 2018, 25th July]: This also works in 3.0.5 official stable.

in Engine by (104 points)
edited by

2 Answers

+1 vote
Best answer

I don't think there is a way to do this on engine level, but it's possible if you simply stop processing input in all your scripts.
You would also need a fullscreen invisible Control on top of everything to prevent mouse input from going through, and give it focus so key/button focus won't access anything.

What is the use case for this?

by (27,774 points)
selected by
+1 vote

Found the solution:
1) add a Control object as the root of the scene
2) add a script to the scene (inherited from "Control")

To disable the input:

get_tree().get_root().set_disable_input(true)

To enable the input:

get_tree().get_root().set_disable_input(false)

Looks like on Windows, even if the input is disabled "Alt +F4" still works though. Everything else is "dead".

by (104 points)
edited by

Oh yeah... there is that, since the game has a default viewport, which is the tree root. It's better than putting a fullscreen Control^^
You still need to stop any script from polling the Input class though.

Couldn't he also pause the tree? It might not work very well if he wants to run physics though.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.