0

I want pressing enter to do the same thing as pressing the search button. There already was a question and it worked for English, but the problem is that it misfires for Japanese input.

In Japanese IME, one presses the enter key to confirm the current input buffer and exit the composition mode, the answer in the existing question also raises the Enter event for this Japanese IME Enter. How can I avoid this?

enter image description here

@page "/"
@using System.Diagnostics

@*<InputText @bind-Value="MyText" @onkeydown="OnTextBoxKeyDown"></InputText>*@
<input @bind="MyText" @bind:event="oninput" @onkeydown="OnTextBoxKeyDown"></input>

<div>
    @foreach(var line in @Log)
    {
        @line <br/>
    }
</div>

@code
{
    string MyText;
    List<string> Log = new List<string>();

    void OnTextBoxKeyDown(KeyboardEventArgs e)
    {
        if (e.Code == "Enter" || e.Code == "NumpadEnter")
        {
            Log.Add($"[{DateTime.Now.ToLongTimeString()}] MyText == [{MyText}]");
            StateHasChanged();
        }
    }
}

Blazor Server-side, .NET 7.0, Microsoft Japanese IME on Windows 11.

Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135

0 Answers0