鍦╳in10涓婏紝濡傛灉瀹夎浜嗘煇浜涜緭鍏ユ硶锛堟瘮濡俀Q杈撳叆娉曪級锛屼細閫犳垚unity鐨勯敭鐩樹簨浠惰杈撳叆娉曟崟鑾疯屼笉鑳借Е鍙戠殑鎯呭喌銆傚彧鏈夊皢杈撳叆娉曞垏鎹㈠埌鑻辨枃鐘舵佷笅鎵嶈兘鍝嶅簲閿洏浜嬩欢銆
瑙e喅鍔炴硶鏈夛紝
1锛氱敤鎴蜂富鍔ㄥ垏鎹㈣緭鍏ユ硶锛岀敋鑷冲嵏杞借緭鍏ユ硶
2锛氱▼搴忓湪闈炶緭鍏ョ姸鎬佷笅锛屽睆钄借緭鍏ユ硶
鐢变簬鏂规硶1鍦ㄥ叏灞忕姸鎬佷笅锛岀敤鎴峰畬鍏ㄤ笉鐭ラ亾鏄惁鍦ㄨ緭鍏ユ硶鍔寔涓紝甯稿父瀵艰嚧浠ヤ负鏄▼搴忕殑bug锛屾墍浠ヨ繖閲岄噰鐢ㄦ柟娉2
鍦╱nity涓紝瀹樻柟骞舵病鏈夋彁渚涗竴涓緢濂界殑瑙e喅鏂规锛圛nput.imeCompositionMode鏃犳晥锛夈傛墍浠ュ彧鑳藉熷姪win api銆
鍏朵腑鏈涓洪噸瑕佺殑API鏄缃緭鍏ユ硶鐘舵侊細
[DllImport("imm32.dll")]
private static extern bool ImmSetOpenStatus(IntPtr himc, bool b);
鍏朵腑himc涓哄綋鍓嶆鍦ㄨ緭鍏ョ殑绐楀彛鐨勮緭鍏ユ硶鍙ユ焺锛宐涓簍rue琛ㄧず寮鍚紝false琛ㄧず鍏抽棴
himc鍙互閫氳繃鍙﹀涓涓猘pi鍑芥暟鑾峰彇
[DllImport("imm32.dll")]
private static extern IntPtr ImmGetContext(IntPtr hwnd);
鍏朵腑锛宧wnd涓虹▼搴忕獥鍙g殑鍙ユ焺
璇ュ肩殑鑾峰彇鏂瑰紡鍙互鍙傝冿細http://blog.csdn.net/linkrules/article/details/50420797
鏁翠釜浠g爜濡備笅锛
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
public class Win32Help
{
private delegate bool Wndenumproc(IntPtr hwnd, uint lParam);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool EnumWindows(Wndenumproc lpEnumFunc, uint lParam);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, ref uint lpdwProcessId);
[DllImport("kernel32.dll")]
private static extern void SetLastError(uint dwErrCode);
/// <summary>
/// 鑾峰彇褰撳墠杩涚▼鐨勭獥鍙e彞鏌
/// </summary>
/// <returns></returns>
public static IntPtr GetProcessWnd()
{
var ptrWnd = IntPtr.Zero;
var pid = (uint)Process.GetCurrentProcess().Id;
// 褰撳墠杩涚▼ ID
var bResult = EnumWindows(delegate (IntPtr hwnd, uint lParam)
{
uint id = 0;
if (GetParent(hwnd) != IntPtr.Zero)
return true;
GetWindowThreadProcessId(hwnd, ref id);
if (id != lParam)
return true;
ptrWnd = hwnd; // 鎶婂彞鏌勭紦瀛樿捣鏉
SetLastError(0); // 璁剧疆鏃犻敊璇
return false; // 杩斿洖 false 浠ョ粓姝㈡灇涓剧獥鍙
}, pid);
return (!bResult && Marshal.GetLastWin32Error() == 0)
? ptrWnd
: IntPtr.Zero;
}
[DllImport("imm32.dll")]
private static extern IntPtr ImmGetContext(IntPtr hwnd);
[DllImport("imm32.dll")]
private static extern bool ImmGetOpenStatus(IntPtr himc);
[DllImport("imm32.dll")]
private static extern bool ImmSetOpenStatus(IntPtr himc, bool b);
/// <summary>
/// 璁剧疆杈撳叆娉曠姸鎬
/// </summary>
/// <param name="tf"></param>
public static void SetImeEnable(bool tf)
{
var handle = GetProcessWnd();
var hIme = ImmGetContext(handle);
ImmSetOpenStatus(hIme, tf);
}
/// <summary>
/// 鑾峰彇杈撳叆娉曠姸鎬
/// </summary>
/// <returns></returns>
public bool GetImeStatus()
{
var handle = GetProcessWnd();
var hIme = ImmGetContext(handle);
return ImmGetOpenStatus(hIme);
}
}鐒跺悗鍦ㄧ▼搴忎腑鍙互浣跨敤Win32Help.SetImeEnable(false)鐨勬柟娉曟潵灞忚斀杈撳叆娉曪紝姣斿锛
using UnityEngine;
public class InputTest : MonoBehaviour
{
// Use this for initialization
protected void Start()
{
Win32Help.SetImeEnable(false);
}
// Update is called once per frame
protected void Update()
{
if (Input.GetKey(KeyCode.A))
{
Debug.Log("AAAAAAAAAAAs");
}
}
}娉ㄦ剰锛氬彧瀵筗indows绯荤粺鏈夋晥锛學in10娴嬭瘯鍙敤锛屽叾浠栫郴缁熸湭缁忔祴璇