Keyboard
How to use the Keyboard class of the bit Butil?
Usage
To use the browser Keyboard features you need to inject the Bit.Butil.Keyboard class and use it like this:
@inject Bit.Butil.Keyboard keyboard
@code {
await keyboard.Add(ButilKeyCodes.F10, args => { ... }, , ButilModifiers.Alt | ButilModifiers.Ctrl);
await keyboard.Remove(ButilKeyCodes.F10, handler);
}Methods
Add, Remove:
Adds/Removes a handler to a keyboard key combination.
@inject Bit.Butil.Keyboard keyboard
<div>Press Ctrl+F to focus on search box</div>
<BitSearchBox @ref="searchBox" />
@code {
private BitSearchBox searchBox = default!;
protected override async Task OnAfterFirstRenderAsync()
{
await keyboard.Add(ButilKeyCodes.KeyF, () => _ = searchBox?.FocusAsync(), ButilModifiers.Ctrl);
}
}