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<InputField>().isFocused|| nametxt.GetComponent<InputField>().isFocused)
        {
            //  Config.GetInstance().UIManage.ShowTouchKeyboard();
            if (TouchKeyboardBoo == false)
            {
                TouchKeyboardBoo = true;
                ShowTouchKeyboard();
            }
        }
        else
        {
            //Config.GetInstance().UIManage.HideTouchKeyboard();
            if (TouchKeyboardBoo == true)
            {
                TouchKeyboardBoo = false;
                HideTouchKeyboard();
            }
        }

    }

    /// 显示屏幕键盘  
    /// </summary>  
    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);
        }
    }
    /// <summary>  
    /// 隐藏屏幕键盘  
    /// </summary>  
    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程序

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hquu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值