Fix LineEdit only being editable via keyboard and mouse
Currently LineEdit actions can only be submitted from Keyboard and Mouse. This is because the event it is listening for is required to be an InputEventKey. To add gamepad support, we just need to move the InputEventKey check below the action checks. I discovered this when I was pressing "submit" on my gamepad and the LineEdit wasn't entering edit mode. When inspecting the source code, I noticed that it required the event be InputEventKey too early. Here's a video of our in game keyboard. We forked it from https://github.com/martinfuchs/Godot-Onscreen-Keyboard. We added gamepad support in our fork here: https://github.com/Lange-Studios/Godot-Onscreen-Keyboard/tree/gamepad-support
https://github.com/user-attachments/assets/77ab91e2-dd12-4005-8d2a-b65dd646f15b
If the letter input has to be done via virtual keyboard, other actions can too, no? I think LineEdit exposes everything necessary for that.
If the letter input has to be done via virtual keyboard, other actions can too, no? I think LineEdit exposes everything necessary for that.
The VirtualKeyboard isn't triggered unless a LineEdit is detected going into edit mode. Then the virtual keyboard appears and starts sending virtual key inputs which the LineEdit processes.
I guess I could implement some logic so that when submit is pressed on the controller it also virtually emits an "Enter" key being pressed. But this will conflict with my other logic that I use to detect if the user is pressing a key on their keyboard or a gamepad controller. I use that logic to determine which tooltips to show the user (gamepad glyphs or keyboard letters). Its a conflict I run into with the virtual keyboard as well, but my virtual keyboard only appears for gamepads. So I can easily perform different detection logic when the virtual keyboard is visible (ie just ignore while visible).
But if I have to emit the enter keystroke on every gamepad ui submit, I'll have to attach some meta data with the event (if I can) to indicate where it came from. And if it came from a gamepad rather than a keyboard, take action accordingly.
Which is actually probably a better approach anyways, but it will require me to refactor the glyph addon I'm using here: https://github.com/rsubtil/controller_icons
Which really isn't that big of a deal. Its probably just a boolean check somewhere. That is of course assuming I can somehow indicate to the receiver of the event that this originated from a gamepad even though its pretending to be a keystroke.
All that to say, yes. You are correct. I can simulate keyboard submit from a user pressing the gamepad. It will just introduce different issues I'll have to work around. This PR shouldn't break or change any existing behavior as far as I can tell. In fact, it should improve on it for mobile users that use a gamepad. Now when users press "enter" on their gamepad on mobile, the mobile built in virtual keypad should appear without requiring the user to use the touch screen. I'm curious on this, I'll go test right now.
It can be done without sending fake events, but yeah, the change is harmless.
It can be done without sending fake events, but yeah, the change is harmless.
Perfect! Well I tested on iOS and unfortunately the ios keyboard wasn't navigable via gamepad. I'm testing Android's now.
I tested on both Android and iOS. I can confirm that this makes it so the gamepad can trigger the native virtual keyboard to appear there! :) So that is an instant improvement for gamepad support on mobile!
The virtual keyboards can't be navigated via the gamepad, but I suspect that is an issue for iOS and Android to resolve and entirely unrelated to Godot.
Good news is this PR does add improved gamepad + mobile support though! And really any platform that implements the virtual keyboard.
Apologies for the delay, this went under the radar. The PR has conflicts and needs to be rebased (unless the conflicts are due to another merged PR doing the same changes).