Blazor 监听键盘输入,并显示!
作者:互联网
Blazor 监听键盘输入,并显示!
我希望能够在不使用 Blazor 中的 HTML INPUT 标记的情况下捕获键盘输入。
@page "/test" <table @ref="testRef" tabindex="0" @onkeydown="HandleKeyDown"> <thead> <tr> <th> Pressed Key </th> </tr> </thead> <tbody> <tr> <td> @pressedKey </td> </tr> </tbody> </table> <h1 @ref="testRef" tabindex="0" @onkeydown="HandleKeyDown">@pressedKey</h1> @code { private ElementReference testRef; private string pressedKey; private void HandleKeyDown(KeyboardEventArgs e) { pressedKey += e.Key; } protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { await testRef.FocusAsync(); } } }
标签:testRef,pressedKey,private,键盘输入,Key,Blazor,监听 来源: https://www.cnblogs.com/kismet82/p/16370411.html