-
Notifications
You must be signed in to change notification settings - Fork 945
Rebase Physical Keys Shortcuts #12570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 20 commits
8d0f5ab
ff56fbc
95d8887
3b62989
addbb72
cbd3def
c19cbf5
367a9ba
2d76209
5aab4cc
29733f5
8bd1424
f4683a4
77cca09
3f98e62
6907839
73d2a6d
d24694d
140985a
6502f4e
9e85f40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ Slint's <Link type="KeyBinding" label="KeyBinding"/> elements and the built-in < | |
| This structure is generated and passed to the key press and release callbacks of the `FocusScope` element. | ||
|
|
||
| - **`text`** (_string_): The unicode representation of the key pressed. | ||
| - **`physical-key`** (_string_): The physical key that was pressed, if the backend reports it. This uses the same names as `@physical-keys(...)`, for example `A`, `Digit1`, or `LeftArrow`. | ||
| - **`modifiers`** (_KeyboardModifiers_): The keyboard modifiers active at the time of the key press event. | ||
| - **`repeat`** (_bool_): This field is set to true for key press events that are repeated, i.e. the key is held down. It's always false for key release events. | ||
|
|
||
|
|
@@ -29,7 +30,7 @@ Slint's <Link type="KeyBinding" label="KeyBinding"/> elements and the built-in < | |
| Use the <Link type="KeyBinding" label="KeyBinding element"/> inside a `FocusScope` to declare key bindings (or keyboard shortcuts). | ||
| The `KeyBinding`'s `keys` property takes an instance of the <Link label="keys type" type="keys"/> and invokes the `activated` callback when the key combination is detected. | ||
|
|
||
| The `keys` type represents a key, combined with modifiers and is constructed with the `@keys` macro. | ||
| The `keys` type represents a key, combined with modifiers and is constructed with either the `@keys` macro for logical keys or the `@physical-keys` macro for physical key positions. | ||
|
|
||
| Key bindings in Slint are based on **logical keys** — the character a keypress produces on the current keyboard layout — not the physical position of a key. | ||
| This means, for example, that `@keys(Control + Z)` activates when the user presses the key that produces `z` on their layout, regardless of where that key sits on the keyboard. | ||
|
|
@@ -101,6 +102,27 @@ This will allow your users to reach the binding on almost all keyboard layouts t | |
|
|
||
| As another example, `@keys(Control + Plus)` is equivalent to `@keys(Control + Shift? + "+")`. | ||
|
|
||
| ### Physical Key Bindings | ||
|
|
||
| If you want to match a physical key position instead of the character produced on the current keyboard layout, use `@physical-keys(..)`. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest to flip it around: "Use Could you include an example (use-case, not code) as well, perhaps? (games?)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done (Added WASD as example) |
||
|
|
||
| Physical key names reuse familiar `Key` names such as `A`, `Digit1`, `BackQuote`, or `LeftArrow`, but they refer to a physical key location instead of logical text. | ||
| Today these names refer to positions on a U.S. keyboard layout. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After yesterday's discussion I feel even more that "Today" should be omitted.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, and reworded it to make it shorter. |
||
| Unlike `@keys(..)`, `@physical-keys(..)` does not currently accept string literals. | ||
|
|
||
| ```slint | ||
| export component Example inherits Window { | ||
| forward-focus: scope; | ||
|
|
||
| scope := FocusScope { | ||
| KeyBinding { | ||
| keys: @physical-keys(Control + A); | ||
| activated => { debug("The physical A key was pressed"); } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Key Namespace | ||
|
|
||
| The `Key` namespace contains a list of well-known logical key codes (including any non-printable characters). | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps here it would also be worthwhile to mention the menu limitation? (or is that overdoing it?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added that onto the docs of the MenuItem.shortcut property now. I think it's unnecessary here, but definitely makes sense there.