Search code examples
windowsflutterfocus

How can I disable default windows hotkeys in flutter desktop application?


I want add new actions for f10 key. But when I press f10 my app loses focus and than I can't track keyboard actions with RawKeyDownEvent.

I want disable all default windows hotkeys while user uses app. Is there any way doing this? Thanks in advance .


Solution

  • you can use this package to register or unregister hotkeys.

    https://pub.dev/packages/hotkey_manager/example

    // ⌥ + Q
    HotKey _hotKey = HotKey(
    KeyCode.keyQ,
    modifiers: [KeyModifier.alt],
    // Set hotkey scope (default is HotKeyScope.system)
    scope: HotKeyScope.inapp, // Set as inapp-wide hotkey.
    );
    await hotKeyManager.register(
    _hotKey,
    keyDownHandler: (hotKey) {
    print('onKeyDown+${hotKey.toJson()}');
    },
    // Only works on macOS.
    keyUpHandler: (hotKey){
    print('onKeyUp+${hotKey.toJson()}');
    } ,
    );
    
    await hotKeyManager.unregister(_hotKey);
    
    await hotKeyManager.unregisterAll();