Skip to content

Commit f67f00d

Browse files
authored
Clarify ignoring joypads on unfocused application (#11680)
2 parents 8c8c973 + b4a7f5f commit f67f00d

File tree

1 file changed

+4
-38
lines changed

1 file changed

+4
-38
lines changed

tutorials/inputs/controllers_gamepads_joysticks.rst

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -222,51 +222,17 @@ with the help of a :ref:`class_Timer` node.
222222
Window focus
223223
~~~~~~~~~~~~
224224

225-
Unlike keyboard input, controller inputs can be seen by **all** windows on the
225+
Unlike keyboard input, controller inputs can by default be seen by **all** windows on the
226226
operating system, including unfocused windows.
227227

228228
While this is useful for
229229
`third-party split screen functionality <https://nucleus-coop.github.io/>`__,
230230
it can also have adverse effects. Players may accidentally send controller inputs
231231
to the running project while interacting with another window.
232232

233-
If you wish to ignore events when the project window isn't focused, you will
234-
need to create an :ref:`autoload <doc_singletons_autoload>` called ``Focus``
235-
with the following script and use it to check all your inputs:
236-
237-
::
238-
239-
# Focus.gd
240-
extends Node
241-
242-
var focused := true
243-
244-
func _notification(what: int) -> void:
245-
match what:
246-
NOTIFICATION_APPLICATION_FOCUS_OUT:
247-
focused = false
248-
NOTIFICATION_APPLICATION_FOCUS_IN:
249-
focused = true
250-
251-
252-
func input_is_action_pressed(action: StringName) -> bool:
253-
if focused:
254-
return Input.is_action_pressed(action)
255-
256-
return false
257-
258-
259-
func event_is_action_pressed(event: InputEvent, action: StringName) -> bool:
260-
if focused:
261-
return event.is_action_pressed(action)
262-
263-
return false
264-
265-
Then, instead of using ``Input.is_action_pressed(action)``, use
266-
``Focus.input_is_action_pressed(action)`` where ``action`` is the name of
267-
the input action. Also, instead of using ``event.is_action_pressed(action)``,
268-
use ``Focus.event_is_action_pressed(event, action)`` where ``event`` is an
269-
InputEvent reference and ``action`` is the name of the input action.
233+
If you wish to ignore controller input events when the project isn't focused,
234+
set :ref:`ProjectSettings.input_devices/joypads/ignore_joypad_on_unfocused_application<class_ProjectSettings_property_input_devices/joypads/ignore_joypad_on_unfocused_application>` to ``true``.
235+
Alternatively, you can also set :ref:`Input.ignore_joypad_on_unfocused_application <class_Input_property_ignore_joypad_on_unfocused_application>` to ``true``.
270236

271237
Power saving prevention
272238
~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)