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