Skip to content

fix(super_hot_key): use KeyboardKey instead of PhysicalKeyboardKey#561

Open
MSOB7YY wants to merge 6 commits into
superlistapp:mainfrom
MSOB7YY:main
Open

fix(super_hot_key): use KeyboardKey instead of PhysicalKeyboardKey#561
MSOB7YY wants to merge 6 commits into
superlistapp:mainfrom
MSOB7YY:main

Conversation

@MSOB7YY
Copy link
Copy Markdown

@MSOB7YY MSOB7YY commented Nov 28, 2025

for some reason, the HotKeyDefinition uses PhysicalKeyboardKey instead of KeyboardKey (

final PhysicalKeyboardKey key;
)

even tho the internal implementation supports KeyboardKey:

int? getPlatformKeyCode(KeyboardKey key) {
if (key is PhysicalKeyboardKey) {
return _physicalToKey[key.usbHidUsage]?.platform;
} else if (key is LogicalKeyboardKey) {
return _logicalToKey[key.keyId]?.platform;
} else {
return null;
}
}

not sure why it wasn't like that, most likely a typo

});

final PhysicalKeyboardKey key;
final KeyboardKey key;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Creating a hotkey with a non-printable LogicalKeyboardKey (e.g., arrow keys) will silently fail and return null because the underlying key map is incomplete.
Severity: MEDIUM

Suggested Fix

Instead of silently returning null for unsupported LogicalKeyboardKeys, the create method should validate the key and throw an informative exception if it's not supported. Alternatively, fully implement support for all LogicalKeyboardKey types in the native code by correctly mapping non-printable keys.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: super_hot_key/lib/super_hot_key.dart#L16

Potential issue: The change from `PhysicalKeyboardKey` to `KeyboardKey` in
`HotKeyDefinition.key` implies full support for `LogicalKeyboardKey`. However, the
underlying implementation only maps logical keys for printable characters. When
attempting to register a hotkey with a non-printable `LogicalKeyboardKey` (e.g.,
`LogicalKeyboardKey.arrowLeft`, function keys), the lookup in the internal
`_logicalToKey` map fails. This causes `getPlatformKeyCode` and subsequently
`HotKey.create()` to return `null` without any warning or exception. This silent failure
can be difficult to debug as developers might assume the hotkey was registered
successfully.

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant