unity输入框点击弹出软键盘

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

using System;

using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;
using UnityEngine.UI;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
public class AdmainUi : MonoBehaviour
{
    
    public InputField nametxt;
    public InputField passtxt;
     
    private bool TouchKeyboardBoo = false;
    [DllImport("user32")]
    static extern IntPtr FindWindow(String sClassName, String sAppName);
    [DllImport("user32")]
    static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
    void Awake()
    {
       
    }

    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
         
        if (passtxt.GetComponent().isFocused|| nametxt.GetComponent().isFocused)
        {
            //  Config.GetInstance().UIManage.ShowTouchKeyboard();
            if (TouchKeyboardBoo == false)
            {
                TouchKeyboardBoo = true;
                ShowTouchKeyboard();
            }
        }
        else
        {
            //Config.GetInstance().UIManage.HideTouchKeyboard();
            if (TouchKeyboardBoo == true)
            {
                TouchKeyboardBoo = false;
                HideTouchKeyboard();
            }
        }

    }

    /// 显示屏幕键盘  
    ///   
    public void ShowTouchKeyboard()
    {
        //UnityEngine.Debug.LogError("@@@@@@@@@@@@@@@  ");
        try
        {
            //IntPtr ptr = FindWindow("IPTip_Main_Window", null);
            //txt.text = ptr.ToString();
            //if ((int)ptr == 0)
            //{
            //    ExternalCall("C:\\Program Files\\Common Files\\Microsoft Shared\\ink\\tabtip.exe", null, false);
            //}
            //  ExternalCall("C:\\Program Files\\Common Files\\Microsoft Shared\\ink\\TabTip.exe", null, false);
            ExternalCall(Application.streamingAssetsPath + "/" + "osk.exe", null, false);
        }
        catch (Exception e)
        {
            UnityEngine.Debug.Log(e);
        }
    }
    ///   
    /// 隐藏屏幕键盘  
    ///   
    public void HideTouchKeyboard()
    {
        try
        {
            uint WM_SYSCOMMAND = 274;
            int SC_CLOSE = 61536;
            IntPtr ptr = FindWindow("IPTip_Main_Window", null);
            PostMessage(ptr, WM_SYSCOMMAND, SC_CLOSE, 0);
        }
        catch (Exception e)
        {
            UnityEngine.Debug.Log(e);
        }
    }
    private static Process ExternalCall(string filename, string arguments, bool hideWindow)
    {
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.FileName = filename;
        startInfo.Arguments = arguments;
        //隐藏控制台
        if (hideWindow)
        {
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError = true;
            startInfo.UseShellExecute = false;
            startInfo.CreateNoWindow = true;
        }
        Process process = new Process();
        process.StartInfo = startInfo;
        process.Start();
        return process;
    }

     


}

  win7系统下,输入框点击后不自动弹出软键盘,我们可以加入一个osc软键盘放入到文件夹中,触发文本后启动osc的exe程序

你可能感兴趣的:(unity,unity,c#,ui)