It is possible to switch keybord's active state via html input's focus event, but it is with some limmitation. Here is an example and this feature has implemented on this sample repositly.
C#
using UnityEngine;
using UnityEngine.EventSystems;
using TLab.VKeyborad;
namespace TLab.WebView.Sample
{
public class FocusInOutInteractionSample : MonoBehaviour, IPointerDownHandler
{
[SerializeField] private SearchBar m_searchBar;
[SerializeField] private BaseInputField m_inputField;
[SerializeField] private BrowserContainer m_container;
public void OnPageFinish(string url)
{
var js = JSUtil.ToVariable("go", gameObject.name) + JSUtil.ToVariable("method", nameof(OnMessage));
js += Resources.Load<TextAsset>("TLab/WebView/Samples/Scripts/JS/focus-in-out-interaction")?.ToString();
m_container.browser.EvaluateJS(js);
}
public void OnMessage(string message)
{
Debug.Log("OnMessage: " + message);
switch (message)
{
case "Focusin":
m_inputField.OnFocus(true);
break;
case "Focusout":
m_inputField.OnFocus(false);
break;
}
}
public void OnPointerDown(PointerEventData eventData) => m_searchBar.OnFocus(false);
}
}
javascript
function searchShadowRoot(node, roots) {
if (node == null) {
return;
}
if (node.shadowRoot != undefined && node.shadowRoot != null) {
roots.push(node.shadowRoot);
searchShadowRoot(node.shadowRoot, roots);
}
for (var i = 0; i < node.childNodes.length; i++) {
searchShadowRoot(node.childNodes[i], roots);
}
}
function getAllRoot() {
var roots = [document];
searchShadowRoot(document, roots);
return roots;
}
var roots = getAllRoot();
function focusin (e) {
const target = e.target;
if (target.tagName == 'INPUT' || target.tagName == 'TEXTAREA') {
window.tlab.unitySendMessage(go, method, 'Focusin');
}
}
function focusout (e) {
const target = e.target;
if (target.tagName == 'INPUT' || target.tagName == 'TEXTAREA') {
window.tlab.unitySendMessage(go, method, 'Focusout');
}
}
for (var i = 0; i < roots.length; i++) {
roots[i].removeEventListener('focusin', focusin);
roots[i].removeEventListener('focusout', focusout);
roots[i].addEventListener('focusin', focusin);
roots[i].addEventListener('focusout', focusout);
}
This approach didn't work on some website because it's impossible to add event listener to iframe's html document if iframe content's server doesn't allow crossorigin access. So above example will work on most of website, but won't work on only some iframe content.
Oculus Quest can use the system keyboard on unity and also works on the TLabWebView
's html input element (this feature is not limited even if iframe). Please see here for how to setup system keyborad on unity.