• Godot Help
  • How to restrict keyboard-events to one Control node?

The situation is, I have a TabPanel with various Tabs, one of which is a "game-panel", a Control-node with sprites, etc. When the game-panel is active, I want to use arrow-keys to move sprites around. I assigned the arrow-keys to various Inputs ("move-left", "move-right", etc). But I'm running into problems with Focus, and how the input-events are processed. When I do an arrow-key left/right, it moves focus across the TabPanel to different tabs (and going away from the game-panel). Wups.

So what I want to do, is restrict keyboard-input to the one Control-node where everything is happening. I've tried things like grab_focus(), which didn't stop the arrow-up from moving focus "up" to the TabPanel,
thereby allowing the arrow-left/right keys to move around the Tabs.

And there do seem to be a lot of knobs that can be adjusted on Focus:

  • focus_mode=click
  • gui_input() to handle events
  • accept_event() to stop events from propagating

But they all seem "piecemeal", or not quite right - Since the TabPanel is at the top of the scene-tree, wouldn't it get the events first?

So, is there a canonical way of restricting keyboard-events to a selected node? Some recommended model? Or do I just have to manually adjust all of the Nodes involved, until they do what I want, with the arrow-keys?

It might not involve focus, either, I've seen references to disabling inputs, but have no idea how that would work on nodes higher in the tree.

    Crawfish why dont u use switches/flags?

    Like for each tab you create enum or something, when that tab is active it sets the active tab var, and you then check which tab is active and then run the input actions based on that?

    Crawfish I think it should be enough to handle your input events in _input() in your game panel and then call get_viewport().set_input_as_handled() to stop it from propagating further. That should prevent the event from reaching GUI controls.