add visual keyboard project
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using System.Diagnostics;
|
||||
|
||||
[RequireComponent(typeof(TMP_InputField))]
|
||||
public class InputFieldManager : MonoBehaviour
|
||||
{
|
||||
private TMP_InputField _inputField = null;
|
||||
private Process _keyboard;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_inputField = GetComponent<TMP_InputField>();
|
||||
if (_inputField != null)
|
||||
{
|
||||
_inputField.onSelect.AddListener(OnInputSelect);
|
||||
_inputField.onDeselect.AddListener(OnInputDeselect);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Debug.LogError("Please add the TMP_InputField component to the object", this);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Return)) CloseKeyboard(); // If enter key pressed, close keyboard
|
||||
}
|
||||
|
||||
private void CloseKeyboard()
|
||||
{
|
||||
KeyboardManager.HideTouchKeyboard();
|
||||
}
|
||||
|
||||
private void LaunchKeyboard()
|
||||
{
|
||||
KeyboardManager.ShowTouchKeyboard();
|
||||
}
|
||||
|
||||
private void OnInputSelect(string pSelectionEvent)
|
||||
{
|
||||
LaunchKeyboard();
|
||||
}
|
||||
|
||||
private void OnInputDeselect(string pSelectionEvent)
|
||||
{
|
||||
CloseKeyboard();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
CloseKeyboard();
|
||||
_inputField.onSelect.RemoveListener(OnInputSelect);
|
||||
_inputField.onDeselect.RemoveListener(OnInputDeselect);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d0fcddaeb8a585e4092a9b5b2bad4779
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public class KeyboardManager
|
||||
{
|
||||
[DllImport("user32")]
|
||||
static extern IntPtr FindWindow(String sClassName, String sAppName);
|
||||
|
||||
[DllImport("user32")]
|
||||
static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
|
||||
|
||||
public static void ShowTouchKeyboard()
|
||||
{
|
||||
try
|
||||
{
|
||||
ExternalCall("C:\\Program Files\\Common Files\\Microsoft Shared\\ink\\tabtip.exe", null, false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UnityEngine.Debug.Log(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static 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();
|
||||
process.Refresh();
|
||||
return process;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54430c850edfe0445bc77c6f4e5e1b57
|
||||
Reference in New Issue
Block a user