Luka Shergelashvili
Luka Shergelashvili

Reputation: 1

How to make virtual keyboard show all the time in Godot 4

in godot 4 I am making a UI game. Each scene is loaded with a lot of LineEdits, and the user needs to type letters in them. However, when I exported the game and tested it on a mobile device, I saw that whenever user is done with, for example, line edit 1 and switches focus on line edit 2 to modify it, the keyboard closes and opens again. Because there are hundreds of line edits in the scene, the constant closing and opening of the keyboard becomes really annoying. Is there a way to keep the keyboard open all the time?

Thank you in advance!

Upvotes: 0

Views: 443

Answers (1)

Bugfish
Bugfish

Reputation: 1729

I got two possible solutions for your problem.

  1. Use a customn on screen keyboard instead of the virtual keyboard of the system.

For example this

This way you also always know how much space the keyboard uses.

  1. If you want to use the system keyboard you can try to use the DisplayServer

It allows you to check, if the system has a virtual keyboard

DisplayServer.has_feature(DisplayServer.FEATURE_VIRTUAL_KEYBOARD)

Then you can hide and show the keyboard manually:

DisplayServer.virtual_keyboard_show("")
DisplayServer.virtual_keyboard_hide()

Without doing all the work my idea would be to make a node, which handles if the virtual keyboard is shown. (Let's call it KeyboardHandler) On ready it looks for every node in the scene that needs a keyboard by iterating the nodes and checking for 'virtual_keyboard_enabled'. It then sets this property to false to make sure only the handler itself triggers the keyboard. Then it conntects a signal to these nodes (e.g focus_entered) to activate the keyboard if it is not visible:

func on_focus_entered():
    if DisplayServer.virtual_keyboard_get_height() == 0:
        displayserver.virtual_keyboard_show("")

Now the Keyboard is only brought up, if it isn't shown at the moment.

Upvotes: 0

Related Questions