1.问题描述:
用W、A、S、D来控制人物行动,当输入框失去焦点的时候,从键盘输入的指令会被第三方输入法屏蔽,效果如下图:
2.解决办法:
原理参见如下两篇博客:
a.http://www.cnblogs.com/CodeGize/p/5612067.html
b.http://blog.csdn.net/thinbug/article/details/53908042
具体代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
using
System.Collections;
using
System.Collections.Generic;
using
UnityEngine;
using
UnityEngine.UI;
using
System;
namespace
GameModel.UI
{
public
class
MonitorTextTyping : MonoBehaviour
{
private
InputField input;
//输入框
public
IntPtr handle;
public
IntPtr imm;
public
static
MonitorTextTyping _instance;
private
void
Awake()
{
//单例
_instance =
this
;
}
// Use this for initialization
void
Start()
{
handle = Win32Help.GetProcessWnd();
imm = Win32Help.GetIme(handle);
input = transform.GetComponent<InputField>();
}
void
Update()
{
if
(!input.isFocused)
{
if
(Win32Help.GetImeStatus(imm))
//如果输入法开了
{
Win32Help.SetImeStatus(imm,
false
);
}
}
else
{
if
(!Win32Help.GetImeStatus(imm))
//如果输入法关了
{
Win32Help.SetImeStatus(imm,
true
);
}
}
}
}
}
|