Game.PSI.VirtualKeyboard
Assembly: Assembly-CSharp
Namespace: Game.PSI
Type: class
Base: TextInputHandler
Summary:
VirtualKeyboard is a TextInputHandler that coordinates with the platform virtual keyboard support to show and dismiss the platform on-screen keyboard when a UI text input gains or loses focus. It reads attributes from the handler proxy ("vk-title", "vk-description", "vk-type") to configure the virtual keyboard appearance and behavior, maps simple string types to the InputType enum, and respects platform pass-through behavior to emulate backspace events when appropriate.
Fields
- None declared in this class.
This class does not introduce any private or public fields; it relies on the base TextInputHandler and global managers (PlatformManager, InputManager, GameManager.UIInputSystem).
Properties
- None declared in this class.
Behavior is implemented via protected overrides and by reading attributes from base.proxy (inherited).
Constructors
public VirtualKeyboard()
Subscribes to PlatformManager.instance.onInputDismissed to receive callbacks when the platform virtual keyboard is dismissed. The handler passed to the event will call RefreshText(text) to update the input text unless the IVirtualKeyboardSupport instance indicates passThroughVKeyboard is true (in which case the platform is expected to pass input events through and automatic refresh is not performed).
Methods
-
private string GetVkTitle()
Reads the "vk-title" attribute from base.proxy. Returns the attribute value if non-empty; otherwise returns the default "Input". Used to supply a title to PlatformManager.ShowVirtualKeyboard. -
private string GetVkDescription()
Reads the "vk-description" attribute from base.proxy. Returns the attribute value if non-empty; otherwise returns an empty string. Used to supply a description or prompt to PlatformManager.ShowVirtualKeyboard. -
private InputType TextToInputType(string text)
Maps a string to an InputType enum using a switch: - "text" => InputType.Text
- "password" => InputType.Password
- "email" => InputType.Email
-
any other string => InputType.Other Used to interpret the "vk-type" attribute.
-
private InputType GetVkType()
Reads the "vk-type" attribute from base.proxy and converts it via TextToInputType. Determines the keyboard input type to request from the platform. -
protected override void OnFocusCallback(string str)
Invoked when the text input gains focus (override from TextInputHandler). If the current control scheme is Gamepad (InputManager.instance.activeControlScheme == InputManager.ControlScheme.Gamepad), requests the platform virtual keyboard: - Calls PlatformManager.instance.ShowVirtualKeyboard(GetVkType(), GetVkTitle(), GetVkDescription(), 100, str)
-
The returned bool indicates whether the platform is providing pass-through text events. If true and PlatformManager.instance.passThroughVKeyboard is true, sets GameManager.UIInputSystem.emulateBackspaceOnTextEvent to true so backspace events are emulated on text events; otherwise leaves emulation disabled. This ensures gamepad-driven UI can open the system keyboard and receive correct text/backspace behavior according to the platform support.
-
protected override void OnBlurCallback()
Invoked when the text input loses focus (override from TextInputHandler). Resets GameManager.UIInputSystem.emulateBackspaceOnTextEvent to false and calls PlatformManager.instance.DismissVirtualKeyboard() to hide the platform keyboard.
Usage Example
// Typical behavior is automatic when a TextInput component uses this handler.
// Example: when the UI text input gains focus while using the Gamepad control scheme,
// VirtualKeyboard.OnFocusCallback will request the platform keyboard using attributes
// from base.proxy (vk-title, vk-description, vk-type) and will adjust emulation behavior.
//
// No explicit initialization is usually required beyond attaching this handler to the text input.
VirtualKeyboard vk = new VirtualKeyboard(); // subscribes to onInputDismissed in ctor
// Ensure base.proxy attributes on the associated handler are set, e.g.:
// proxy.SetAttribute("vk-type", "text");
// proxy.SetAttribute("vk-title", "Enter name");
// proxy.SetAttribute("vk-description", "City name");
Additional notes: - Supported vk-type values: "text", "password", "email" (any other value yields InputType.Other). - If PlatformManager.instance.passThroughVKeyboard is true, the platform will pass input events through and the class will avoid calling RefreshText on dismissal; emulation of backspace is toggled to allow correct handling of backspace via text events. - The class depends on global singletons: PlatformManager, InputManager, and GameManager.UIInputSystem. Ensure those are available in your mod context.