A powerful .NET MAUI library for global keyboard capture with strong support for barcode scanners. Provides system-wide key interception, hotkeys management.
Demo application showing key capture, barcode scanning, and hotkeys functionality
- 🔑 Global keyboard capture
- 📊 Advanced keyboard input processing
- 🏷️ Built-in barcode scanner support
- ⌨️ Customizable hotkeys system
- 📱 Cross-platform (Windows & Android)
- 🎛️ Highly configurable
- 🧩 Easy to integrate
- 🔧 Built for .NET MAUI
- Barcode scanner integration
- Global hotkeys and shortcuts
- System-wide keyboard monitoring
- Custom keyboard input handling
- Input automation
- Multi-mode keyboard capture
- Standard keys (A-Z, 0-9)
- Function keys (F1-F24)
- Modifier keys (Ctrl, Alt, Shift)
- Windows OEM keys (;, /, [, ], etc)
- Android special keys (Volume, Back, Menu)
- Navigation keys
- Special characters
dotnet add package GlobalKeyboardCapture.Maui
Or via the NuGet Package Manager:
Install-Package GlobalKeyboardCapture.Maui
- Register the service in your
MauiProgram.cs
:
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseKeyboardHandling();
builder.Services.AddKeyboardHandling(options =>
{
// Barcode specific settings
options.BarcodeTimeout = 150;
options.MinBarcodeLength = 8;
});
return builder.Build();
}
- Basic usage example:
public partial class MainPage : ContentPage
{
private readonly IKeyHandlerService _keyHandlerService;
private readonly BarcodeHandler _barcodeHandler;
private readonly HotkeyHandler _hotkeyHandler;
public MainPage(
IKeyHandlerService keyHandlerService,
BarcodeHandler barcodeHandler,
HotkeyHandler hotkeyHandler)
{
InitializeComponent();
_keyHandlerService = keyHandlerService;
_barcodeHandler = barcodeHandler;
_hotkeyHandler = hotkeyHandler;
SetupHandlers();
}
private void SetupHandlers()
{
// Setup barcode handling
_barcodeHandler.BarcodeScanned += (sender, input) =>
{
MainThread.BeginInvokeOnMainThread(() =>
{
ProcessInput(input);
});
};
// Setup global hotkeys
_hotkeyHandler.RegisterHotkey("F2", () =>
{
EnableEditMode();
});
// Register handlers
_keyHandlerService.RegisterHandler(_barcodeHandler);
_keyHandlerService.RegisterHandler(_hotkeyHandler);
}
}
Create your own key handler for specific needs:
public class CustomKeyHandler : IKeyHandler
{
public bool ShouldHandle(string key) => true;
public void HandleKey(string key)
{
// Your custom key handling logic
}
}
The library features a smart hotkey normalization system that allows flexible registration of keyboard shortcuts:
// Single key hotkeys
_hotkeyHandler.RegisterHotkey("F2", EnableEditMode);
_hotkeyHandler.RegisterHotkey("ESC", CancelOperation);
// All these registrations trigger the same hotkey (Ctrl+Alt+Shift+P)
_hotkeyHandler.RegisterHotkey("Ctrl+Alt+Shift+P", PrintAction);
_hotkeyHandler.RegisterHotkey("Shift+Ctrl+Alt+P", PrintAction);
_hotkeyHandler.RegisterHotkey("Alt+Shift+Control+P", PrintAction);
// Supports common aliases
_hotkeyHandler.RegisterHotkey("Control+Alt+P", PrintAction); // "Control" is normalized to "Ctrl"
_hotkeyHandler.RegisterHotkey("Windows+Shift+X", ActionX); // "Windows" is normalized to "Win"
// Case-insensitive handling
_hotkeyHandler.RegisterHotkey("CTRL+ALT+P", PrintAction);
_hotkeyHandler.RegisterHotkey("ctrl+alt+p", PrintAction);
//Special keys
_hotkeyHandler.RegisterHotkey("VolumeUp", VolumeControlAction); //Android Volume Up
_hotkeyHandler.RegisterHotkey("OEM173", VolumeControlAction); //OEM 173
The hotkey system provides:
- Automatic normalization of modifier order (Ctrl → Alt → Shift → Win)
- Case-insensitive handling
- Common alias support (e.g., "Control" → "Ctrl")
- Consistent behavior regardless of registration order
- High-performance implementation with minimal allocations
_barcodeHandler.BarcodeScanned += (sender, input) =>
{
ProcessProduct(input);
};
The library is optimized for performance and efficiency:
- Minimal Allocations: Uses modern .NET features to minimize garbage collection pressure
- Fast Lookups: Optimized dictionary implementations for hotkey matching
- Efficient String Handling: Smart string comparison and normalization
- Aggressive Inlining: Critical paths are optimized for speed
- Memory Efficiency: Careful management of memory allocations in hot paths
- Capture keyboard input regardless of focus
- Works with all UI controls
- System-wide key interception
- Configurable input timeout
- Input validation and filtering
- Custom processing rules
- Windows desktop applications
- Android mobile applications
- Consistent API across platforms
IKeyHandlerService
: Main service for global keyboard handlingBarcodeHandler
: Specialized handler for barcode input scenariosHotkeyHandler
: Global hotkeys management
IKeyHandler
: Base interface for custom handlersILifecycleHandler
: Application lifecycle management
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Anderson Fernandes do Nascimento
If you encounter any issues or need help, please open an issue.