解决二次打开网页,还是在上次滑动的位置,没有回到顶点的原因:
lianJie_ZiXun.transform.GetChild(index).GetComponent<CanvasWebViewPrefab>().WebView.ExecuteJavaScript("window.scrollTo(0, 0);");
输入中文查询:
public CanvasWebViewPrefab canvasWebViewPrefab;
public CanvasKeyboard canvasKeyboard;
HardwareKeyboardListener _hardwareKeyboardListener;
private EventSystem _eventSystem;
// Start is called before the first frame update
void Start()
{
//_eventSystem = EventSystem.current;
inputField.onEndEdit.AddListener((text) =>
{
canvasWebViewPrefab.WebView.SendKey("document.activeElement.value = '" + text + "'");
});
canvasWebViewPrefab.InitialUrl = "http://123.232.102.30:59994/college/tutorList.html";
// Async_等待web初始化并打开网址(ST_数组_网址[0]);
Async_判断是否聚焦在输入框内来显隐键盘();
Async_网页键盘给输入框传输字符();
}
async void Async_判断是否聚焦在输入框内来显隐键盘()
{
await canvasKeyboard.WaitUntilInitialized();
canvasKeyboard.gameObject.SetActive(false);
await canvasWebViewPrefab.WaitUntilInitialized();
canvasWebViewPrefab.WebView.FocusedInputFieldChanged += (sender, eventArgs) =>
{
var shouldShowKeyboard = eventArgs.Type != FocusedInputFieldType.None;
//canvasKeyboard.gameObject.SetActive(shouldShowKeyboard);
inputField.gameObject.SetActive(true);
//inputField.ActivateInputField(true);
keyboard = Process.Start("C:\\Windows\\System32\\osk.exe");
inputField.Select();
//_eventSystem.SetSelectedGameObject(inputField.gameObject, new BaseEventDate(_eventSystem));
};
}
async void Async_网页键盘给输入框传输字符()
{
await canvasWebViewPrefab.WaitUntilInitialized();
var webViewWithKeyDownAndUp = canvasWebViewPrefab.WebView as IWithKeyDownAndUp;
_hardwareKeyboardListener = HardwareKeyboardListener.Instantiate();
_hardwareKeyboardListener.KeyDownReceived += (sender, eventArgs) => {
if (webViewWithKeyDownAndUp != null)
{
webViewWithKeyDownAndUp.KeyDown(eventArgs.Value, eventArgs.Modifiers);
}
else
{
canvasWebViewPrefab.WebView.SendKey(eventArgs.Value);
}
};
_hardwareKeyboardListener.KeyUpReceived += (sender, eventArgs) => {
webViewWithKeyDownAndUp?.KeyUp(eventArgs.Value, eventArgs.Modifiers);
};
canvasKeyboard.InputReceived += (sender, eventArgs) => {
canvasWebViewPrefab.WebView.SendKey(eventArgs.Value);
};
}