Skip to content
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

Raw Hotkeys #115

Open
johnny-smitherson opened this issue Jun 2, 2024 · 2 comments
Open

Raw Hotkeys #115

johnny-smitherson opened this issue Jun 2, 2024 · 2 comments
Assignees
Labels
feature New feature or request
Milestone

Comments

@johnny-smitherson
Copy link

johnny-smitherson commented Jun 2, 2024

Hello

I'm trying to achieve this example

use_hotkeys!(("controlleft") => move |_| {

Which is capturing when the Ctrl or Shift key pressed by itself (not a part of a combination like Ctrl+S).

But the callback for controlleft controlright does not trigger like suggested in the example above (never logs that text to console). Tested both ff and chrome

I see this switch

match part.to_lowercase().as_str() {

It seems the key is only pushed to the thing if it's not a modifier.
This means we cannot capture events if only key pressed is modifier.

Which means we can't implement tetris: Shift and C are to hold. Ctrl and Z are to rotate 90° counterclockwise


But, say the switch above is changed to put the Ctrl both in the key codes and in the modifiers. That means we might have to match it using Ctrl+ControlLeft instead of just ControlLeft.

But then, when you throw the Shift key into the controls, and the user is mashing the keys in a desperate manner, a Ctrl keydown followed by Shift keydown (before the Ctrl keyup) might be seen as Ctrl+Shift+LeftShift, which will not match Shift+LeftShift

tl;dr Do you foresee any option to treat modifier keys as normal keys (to avoid the complications above)? Maybe separate use_raw_hotkeys! that gives the key codes without pre-processing the modifiers

@johnny-smitherson
Copy link
Author

The macro defs are pretty gnarly maybe more of them is not a good idea

As workaround we commented out all mentions of Ctrl or Shift in leptos-hotkeys/leptos_hotkeys/src/hotkey.rs

@friendlymatthew
Copy link
Member

Hi @johnny-smitherson sorry for the delay.

There isn't any specific reason why, when I was writing this I noticed a lot of other libraries followed such conventions.

Raw hotkeys sound cool and doable. Best of luck with Tetris! Would love to see it at the end :)

@friendlymatthew friendlymatthew self-assigned this Jun 11, 2024
@friendlymatthew friendlymatthew added the feature New feature or request label Jun 11, 2024
@friendlymatthew friendlymatthew changed the title no detection of modifier keys pressed by themselves: ControlLeft, ControlRight, ShiftLeft, ShiftRight Raw Hotkeys Jun 11, 2024
@friendlymatthew friendlymatthew added this to the v0.3.0 milestone Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants