JavaScript
function initialize() {
window.addEventListener("keydown", handleKeydown);
function handleKeydown(event) {
var keyCode = event.keyCode;
// Enter key
if (keyCode == 13) {
window.chrome.webview.postMessage("Enter Key Down");
}
}
}
イベントの追加
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
await webView.EnsureCoreWebView2Async(null);
webView.CoreWebView2.WebMessageReceived += GetMessage;
}
private void GetMessage(object sender, CoreWebView2WebMessageReceivedEventArgs e)
{
if (e.TryGetWebMessageAsString() == "Enter Key Down")
{
textBox.Focus();
textBox.SelectAll();
}
}