Search Unity

Question Controlling the position of the Windows On Screen Keyboard in Unity

Discussion in 'Scripting' started by PatrykBroda, Feb 15, 2024.

  1. PatrykBroda

    PatrykBroda

    Joined:
    Oct 6, 2020
    Posts:
    2
    Hello I am looking to control the Unity OSK in a Unity c# script however I am having trouble I have been trying to debug it and whatever happens it fails I tried launching the editor in admin mode yet I am still hitting my debug error.


    public IEnumerator PositionOSKBottomLeft()
    {
    yield return new WaitForSeconds(3);
    // Find the OSK window
    IntPtr oskWnd = FindWindow("OSKMainClass", null);
    if (oskWnd != IntPtr.Zero)
    {
    UnityEngine.Debug.Log("OSK window found.");
    bool setPositionSuccess = SetWindowPos(oskWnd, HWND_TOPMOST, 0, Screen.height - 300, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
    if (setPositionSuccess)
    {
    UnityEngine.Debug.LogError("OSK position set successfully.");
    }
    else
    {
    UnityEngine.Debug.LogError("Failed to set OSK position.");
    }
    }
    else
    {
    UnityEngine.Debug.LogError("OSK window not found.");
    }
    yield return null;
    }



    I have been looking around and there isn't much information on how to do this.