fix modifier detection

This commit is contained in:
Jonas Bark
2025-11-07 20:36:35 +01:00
parent c66badf39e
commit a9a13be6ca
4 changed files with 25 additions and 20 deletions

View File

@@ -1,6 +1,7 @@
### 3.3.1 (unreleased)
### 3.4.0 (unreleased)
**New Features:**
- Support for Shimano Di2
- Support Keyboard shortcuts with modifier keys (Ctrl, Alt, Shift, ...)
**Fixes:**
- fix detection of Elite Square Sterzo devices

View File

@@ -418,7 +418,10 @@ class KeypairExplanation extends StatelessWidget {
)
else if (keyPair.physicalKey != null && actionHandler.supportedModes.contains(SupportedMode.keyboard)) ...[
_KeyWidget(
label: keyPair.logicalKey?.keyLabel ?? 'Unknown',
label: [
...keyPair.modifiers.map((e) => e.name.replaceAll('Modifier', '')),
keyPair.logicalKey?.keyLabel ?? 'Unknown',
].joinToString(separator: '+'),
),
if (keyPair.isLongPress) Text('long\npress', style: TextStyle(fontSize: 10)),
] else ...[

View File

@@ -58,6 +58,7 @@ class _HotKeyListenerState extends State<HotKeyListenerDialog> {
final wasModifier = _updateModifierState(event.logicalKey, add: true);
// Regular key pressed - record it along with active modifiers
if (!wasModifier) {
if (_pressedKey?.logicalKey != event.logicalKey) {}
_pressedKey = event;
widget.customApp.setKey(
_pressedButton!,
@@ -76,27 +77,27 @@ class _HotKeyListenerState extends State<HotKeyListenerDialog> {
bool _updateModifierState(LogicalKeyboardKey key, {required bool add}) {
ModifierKey? modifier;
if (key == LogicalKeyboardKey.shift ||
key == LogicalKeyboardKey.shiftLeft ||
if (key == LogicalKeyboardKey.shift ||
key == LogicalKeyboardKey.shiftLeft ||
key == LogicalKeyboardKey.shiftRight) {
modifier = ModifierKey.shiftModifier;
} else if (key == LogicalKeyboardKey.control ||
key == LogicalKeyboardKey.controlLeft ||
key == LogicalKeyboardKey.controlRight) {
} else if (key == LogicalKeyboardKey.control ||
key == LogicalKeyboardKey.controlLeft ||
key == LogicalKeyboardKey.controlRight) {
modifier = ModifierKey.controlModifier;
} else if (key == LogicalKeyboardKey.alt ||
key == LogicalKeyboardKey.altLeft ||
key == LogicalKeyboardKey.altRight) {
} else if (key == LogicalKeyboardKey.alt ||
key == LogicalKeyboardKey.altLeft ||
key == LogicalKeyboardKey.altRight) {
modifier = ModifierKey.altModifier;
} else if (key == LogicalKeyboardKey.meta ||
key == LogicalKeyboardKey.metaLeft ||
key == LogicalKeyboardKey.metaRight) {
} else if (key == LogicalKeyboardKey.meta ||
key == LogicalKeyboardKey.metaLeft ||
key == LogicalKeyboardKey.metaRight) {
modifier = ModifierKey.metaModifier;
} else if (key == LogicalKeyboardKey.fn) {
modifier = ModifierKey.functionModifier;
}
if (modifier != null) {
if (add) {
_activeModifiers.add(modifier);
@@ -123,13 +124,13 @@ class _HotKeyListenerState extends State<HotKeyListenerDialog> {
if (key == null) {
return _activeModifiers.isEmpty ? 'Waiting...' : '${_activeModifiers.map(_formatModifierName).join('+')}+...';
}
if (_activeModifiers.isEmpty) {
return key.logicalKey.keyLabel;
}
final modifierStrings = _activeModifiers.map(_formatModifierName);
return '${modifierStrings.join('+')}+${key.logicalKey.keyLabel}';
}

View File

@@ -8,7 +8,6 @@ import 'package:swift_control/main.dart';
import 'package:swift_control/pages/device.dart';
import 'package:swift_control/utils/actions/base_actions.dart';
import 'package:swift_control/utils/keymap/apps/custom_app.dart';
import 'package:swift_control/utils/keymap/apps/my_whoosh.dart';
import 'package:swift_control/utils/keymap/keymap.dart';
import 'package:swift_control/utils/keymap/manager.dart';
import 'package:swift_control/widgets/button_widget.dart';
@@ -145,7 +144,7 @@ class _ButtonEditor extends StatelessWidget {
@override
Widget build(BuildContext context) {
final actions = <PopupMenuEntry>[
if (settings.getMyWhooshLinkEnabled() && settings.getTrainerApp() is MyWhoosh)
if (settings.getMyWhooshLinkEnabled() && whooshLink.isCompatible(settings.getLastTarget()!))
PopupMenuItem<PhysicalKeyboardKey>(
child: PopupMenuButton(
itemBuilder: (_) => WhooshLink.supportedActions.map(
@@ -372,6 +371,7 @@ class _ButtonEditor extends StatelessWidget {
keyPair.isLongPress = false;
keyPair.physicalKey = null;
keyPair.logicalKey = null;
keyPair.modifiers = [];
keyPair.touchPosition = Offset.zero;
keyPair.inGameAction = null;
keyPair.inGameActionValue = null;