fix: Keyboard remapping with arrow keys

This commit is contained in:
PartyDonut 2025-08-15 11:53:33 +02:00
parent 8ec4c79ad3
commit 5250b002c5

View file

@ -97,6 +97,9 @@ class KeyListenerWidgetState extends ConsumerState<KeyListenerWidget> {
void setIsListening(bool value) { void setIsListening(bool value) {
changingShortCut = value; changingShortCut = value;
_isListening = value; _isListening = value;
if (value) {
focusNode.requestFocus();
}
} }
@override @override
@ -132,13 +135,13 @@ class KeyListenerWidgetState extends ConsumerState<KeyListenerWidget> {
}); });
} }
void _handleKeyEvent(KeyEvent event) { KeyEventResult _handleKeyEvent(FocusNode node, KeyEvent event) {
final videoHotKeys = ref.read(videoPlayerSettingsProvider.select((value) => value.currentShortcuts)).values; final videoHotKeys = ref.read(videoPlayerSettingsProvider.select((value) => value.currentShortcuts)).values;
final clientHotKeys = ref.read(clientSettingsProvider.select((value) => value.currentShortcuts)).values; final clientHotKeys = ref.read(clientSettingsProvider.select((value) => value.currentShortcuts)).values;
final activeHotKeys = [...videoHotKeys, ...clientHotKeys].toList(); final activeHotKeys = [...videoHotKeys, ...clientHotKeys].toList();
if (_isListening) { if (_isListening) {
focusNode.requestFocus(); node.requestFocus();
setState(() { setState(() {
if (event is KeyDownEvent) { if (event is KeyDownEvent) {
if (KeyCombination.modifierKeys.contains(event.logicalKey)) { if (KeyCombination.modifierKeys.contains(event.logicalKey)) {
@ -167,9 +170,11 @@ class KeyListenerWidgetState extends ConsumerState<KeyListenerWidget> {
} }
} }
}); });
return KeyEventResult.handled;
} else { } else {
_pressedKey = null; _pressedKey = null;
_pressedModifier = null; _pressedModifier = null;
return KeyEventResult.ignored;
} }
} }
@ -184,12 +189,16 @@ class KeyListenerWidgetState extends ConsumerState<KeyListenerWidget> {
final currentModifier = _pressedModifier ?? (widget.currentKey?.modifier); final currentModifier = _pressedModifier ?? (widget.currentKey?.modifier);
final currentKey = _pressedKey ?? widget.currentKey?.key; final currentKey = _pressedKey ?? widget.currentKey?.key;
final currentHotKey = currentKey == null ? null : KeyCombination(key: currentKey, modifier: currentModifier); final currentHotKey = currentKey == null ? null : KeyCombination(key: currentKey, modifier: currentModifier);
return MouseRegion( return Focus(
focusNode: focusNode,
onKeyEvent: _handleKeyEvent,
child: MouseRegion(
onEnter: (event) => showClearButton(true), onEnter: (event) => showClearButton(true),
onExit: (event) => showClearButton(false), onExit: (event) => showClearButton(false),
child: ClipRRect( child: ClipRRect(
borderRadius: FladderTheme.smallShape.borderRadius, borderRadius: FladderTheme.smallShape.borderRadius,
child: InkWell( child: InkWell(
canRequestFocus: false,
onTap: _isListening ? _stopListening : _startListening, onTap: _isListening ? _stopListening : _startListening,
onSecondaryTap: () { onSecondaryTap: () {
setState(() { setState(() {
@ -228,23 +237,19 @@ class KeyListenerWidgetState extends ConsumerState<KeyListenerWidget> {
), ),
), ),
if (_isListening) if (_isListening)
Positioned.fill( const Positioned.fill(
child: KeyboardListener( child: Opacity(
focusNode: focusNode,
autofocus: true,
onKeyEvent: _handleKeyEvent,
child: const Opacity(
opacity: 0.25, opacity: 0.25,
child: LinearProgressIndicator(), child: LinearProgressIndicator(),
), ),
), ),
),
], ],
), ),
), ),
), ),
), ),
), ),
),
); );
} }
} }