Forum rules - please read before posting.

Issue with Virtual Keyboard

Hi all,

Hope you are doing well!
I'm curious to know -- has anyone here successfully integrated the steam virtual keyboard in their game?

`using UnityEngine;
using Steamworks;
using TMPro;
using System.Collections;

public class SteamDeckVirtualKeyboard : MonoBehaviour
{
public TMP_InputField inputField;
public string promptText = "Please enter text";
public int maxCharLimit = 300; //max char limit for input

private void Start()
{
    if (SteamManager.Initialized)
    {
        inputField.onSelect.AddListener(ShowVirtualKeyboard);
    }
}

private void ShowVirtualKeyboard(string selected)
{
    // Check if the game is running on a Steam Deck
    if (SteamUtils.IsSteamRunningOnSteamDeck())
    {
        Debug.Log("IS RUNNING ON STEAM DECK");

        // Show the Steam Deck virtual keyboard
        bool isShowing = SteamUtils.ShowGamepadTextInput(
            EGamepadTextInputMode.k_EGamepadTextInputModeNormal,
            EGamepadTextInputLineMode.k_EGamepadTextInputLineModeSingleLine, 
            promptText, // virtual keyboard input description
            (uint)maxCharLimit, // max num of chars
            inputField.text // existing text from the input field
        );

        if (isShowing)
        {
            // Start the coroutine to check for text submission
            StartCoroutine(CheckForSubmit());
        }
    }
    else
    {
        Debug.Log("NOT RUNNING ON STEAM DECK");
    }
}

private IEnumerator CheckForSubmit()
{
    // Wait until the overlay (virtual keyboard) is closed
    while (SteamUtils.IsOverlayEnabled())
    {
        yield return null;
    }

    // After the overlay is closed, retrieve the text
    string enteredText;
    uint bufferSize = (uint)maxCharLimit;

    bool success = SteamUtils.GetEnteredGamepadTextInput(out enteredText, bufferSize);
    if (success)
    {
        Debug.Log("ENTERED TEXT: " + enteredText);
        inputField.text = enteredText; // Update the input field
    }
    else
    {
        Debug.LogWarning("Failed to retrieve entered text from the virtual keyboard.");
    }
}

}
`

It looks like while the keyboard opens up, I'm unable to grab the text. it looks like enteredText is actually empty. So I'm curious to know two things --

A) check if the user has pressed the "submit" button when the keyboard pops up and

B) Successfully retrieve the entire content of the text in the text popup when the user presses "submit".

If it helps, I'm attaching my steamworks discussions as further context: https://steamcommunity.com/groups/steamworks/discussions/0/4630357120383984911/

Any help is appreciated, thank you! :)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.