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,62 +189,62 @@ 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(
onEnter: (event) => showClearButton(true), focusNode: focusNode,
onExit: (event) => showClearButton(false), onKeyEvent: _handleKeyEvent,
child: ClipRRect( child: MouseRegion(
borderRadius: FladderTheme.smallShape.borderRadius, onEnter: (event) => showClearButton(true),
child: InkWell( onExit: (event) => showClearButton(false),
onTap: _isListening ? _stopListening : _startListening, child: ClipRRect(
onSecondaryTap: () { borderRadius: FladderTheme.smallShape.borderRadius,
setState(() { child: InkWell(
setIsListening(false); canRequestFocus: false,
widget.onChanged(null); onTap: _isListening ? _stopListening : _startListening,
}); onSecondaryTap: () {
}, setState(() {
child: Container( setIsListening(false);
color: Theme.of(context).colorScheme.primaryContainer, widget.onChanged(null);
child: AnimatedSize( });
duration: const Duration(milliseconds: 125), },
child: Stack( child: Container(
alignment: Alignment.center, color: Theme.of(context).colorScheme.primaryContainer,
children: [ child: AnimatedSize(
Padding( duration: const Duration(milliseconds: 125),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), child: Stack(
child: Row( alignment: Alignment.center,
spacing: 8, children: [
children: [ Padding(
if (_showClearButton && currentHotKey != null) padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
GestureDetector( child: Row(
onTap: () { spacing: 8,
setIsListening(false); children: [
widget.onChanged(null); if (_showClearButton && currentHotKey != null)
}, GestureDetector(
child: const Icon( onTap: () {
IconsaxPlusLinear.trash, setIsListening(false);
size: 17, widget.onChanged(null);
},
child: const Icon(
IconsaxPlusLinear.trash,
size: 17,
),
), ),
Text(
currentHotKey?.label ?? "+",
style: Theme.of(context).textTheme.bodyMedium?.copyWith(fontWeight: FontWeight.bold),
), ),
Text( ],
currentHotKey?.label ?? "+", ),
style: Theme.of(context).textTheme.bodyMedium?.copyWith(fontWeight: FontWeight.bold),
),
],
), ),
), if (_isListening)
if (_isListening) const Positioned.fill(
Positioned.fill( child: Opacity(
child: KeyboardListener(
focusNode: focusNode,
autofocus: true,
onKeyEvent: _handleKeyEvent,
child: const Opacity(
opacity: 0.25, opacity: 0.25,
child: LinearProgressIndicator(), child: LinearProgressIndicator(),
), ),
), ),
), ],
], ),
), ),
), ),
), ),