BlazorVirtualKeyboard 1.0.2

dotnet add package BlazorVirtualKeyboard --version 1.0.2
                    
NuGet\Install-Package BlazorVirtualKeyboard -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlazorVirtualKeyboard" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BlazorVirtualKeyboard" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="BlazorVirtualKeyboard" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BlazorVirtualKeyboard --version 1.0.2
                    
#r "nuget: BlazorVirtualKeyboard, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=BlazorVirtualKeyboard&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=BlazorVirtualKeyboard&version=1.0.2
                    
Install as a Cake Tool

Blazor On-Screen Virtual Keyboard

A lightweight on-screen keyboard for Blazor WebAssembly (.NET 8) with minimal JavaScript dependencies.
Supports multiple languages, numeric keypad (numpad) for number inputs, and customizable layouts.

πŸš€ Current Status:
Blazor WebAssembly is fully supported. Blazor Server support is in progress.

⚠ Note: This is a prototype and may not support all use cases. Due to the interaction between Blazor and JavaScript, only the components FormVirtualKeyboard.razor and InputVirtualKeyboard.razor currently support this keyboard.


✨ Features

βœ” On-screen virtual keyboard for Blazor WebAssembly
βœ” Supports multiple languages (English, Danish, and more planned)
βœ” Numeric keypad (numpad) support for `<InputVirtualkeyboard Id="number" Type="number/> fields
βœ” Includes special characters (€, @, %, &, etc.)
βœ” Customizable keyboard layouts (QWERTY, AZERTY, DVORAK – planned)
βœ” Minimal JavaScript usage for better Blazor integration
βœ” Automatic focus detection – The keyboard activates when an input field is focused


πŸ“Έ Screenshots

Alphabetic Layout:

Alphabetic keyboard

Special Characters:

Alphabetic keyboard

Numpad:

Alphabetic keyboard


πŸ“¦ Installation

Install the NuGet package in your Blazor WebAssembly project (.NET 8):

dotnet add package BlazorVirtualKeyboard

1️⃣ Update Program.cs

Add the following services:

builder.Services.AddHttpClient(); 
builder.Services.AddScoped<BlazorVirtualKeyboard.Services.VirtualKeyboardService>();

2️⃣ Add Namespace

In _Imports.razor, add:

@using BlazorVirtualKeyboard 

3️⃣ Add Scripts in index.html

Ensure the following scripts are included:

<script src="_content/BlazorVirtualKeyboard/Components/InputVirtualKeyboard.razor.js"></script> 
<script src="_content/BlazorVirtualKeyboard/Components/FormVirtualKeyboard.razor.js"></script> 
<script src="_content/BlazorVirtualKeyboard/Keyboards/VirtualKeyboard.razor.js"></script>

(Optional, but recommended) If you want function button icons, include:

<script src="https://kit.fontawesome.com/be5149d719.js" crossorigin="anonymous"></script>

πŸš€ Usage

Basic Setup

To enable the keyboard globally, add it once in MainLayout.razor:

<div>
    <BlazorVirtualKeyboard.Keyboards.VirtualKeyboard />
</div>

The keyboard remains hidden until a compatible input field is focused.

Form Example (Login)

Here’s how to integrate it into a form:

<FormVirtualKeyboard FormAction="Login" FormId="loginForm" FormClass="login-form row-1 test-form" EditContext="loginEditContext">
    <h5>Login</h5>
    <div class="input">
        <label for="username" />
        <InputVirtualKeyboard @bind-InputValue="LoginModelInstance.Username"
                              Id="username" Type="text" Placeholder="Username" />

        <label for="password" />
        <InputVirtualKeyboard @bind-InputValue="LoginModelInstance.Password"
                              Id="password" Type="password" Placeholder="Password" />
    </div>
    <div class="action">
        <button type="submit" class="bluebtn">
            Login
        </button>
    </div>
</FormVirtualKeyboard>

@code {
    public LoginModel? LoginModelInstance = new LoginModel();
    private EditContext? loginEditContext;

    protected override async Task OnInitializedAsync()
    {
        loginEditContext = new EditContext(LoginModelInstance);
    }

    private void Login()
    {
        if (loginEditContext.Validate())
        {
            Log.Information($"User: {LoginModelInstance?.Username}, Password: {LoginModelInstance?.Password}");
        }
    }

    public class LoginModel
    {
        [Required]
        [MinLength(3, ErrorMessage = "Username is too short.")]
        public string? Username { get; set; }

        [Required]
        [MinLength(3, ErrorMessage = "Password is too short.")]
        public string? Password { get; set; }
    }
}

Numeric Keypad Example

For <input type="number">, you can enable the numpad:

<InputVirtualKeyboard Placeholder="Enter a number" Id="numInput" Type="number"/>

Standalone Input Field

If you just need an input with the virtual keyboard:

<InputVirtualKeyboard Placeholder="Type here" Id="test" Type="text"/>

πŸ”œ Planned Features

  • βœ… Blazor Server support (in progress)
  • 🎨 Customizable layouts (QWERTY, AZERTY, DVORAK, etc.)
  • 🌍 More language support (user-configurable layouts)
  • πŸ”’ Expanded numpad functionality (arithmetic operations, decimal input)
  • πŸ– Theme customization (light/dark mode, colors, CSS variables)
  • 🎹 Custom keyboard mappings (for specialized applications)

πŸ›  Troubleshooting

  • Keyboard not appearing? Make sure you included the required scripts in index.html.
  • Keyboard not closing? Ensure you don’t have conflicting JavaScript handling focus events.
  • Blazor Server not working? Server support is still in development.

πŸ“„ License

This project is licensed under the MIT License.


🀝 Contributing

Feel free to report issues, suggest features, or submit pull requests! Contributions are welcome. πŸš€

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 440 7/15/2024
1.0.1 130 7/15/2024 1.0.1 is deprecated because it is no longer maintained.