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

Support separate keydown/keyup event for hotkey #9

Closed
morajabi opened this issue Jan 17, 2023 · 4 comments · Fixed by #34
Closed

Support separate keydown/keyup event for hotkey #9

morajabi opened this issue Jan 17, 2023 · 4 comments · Fixed by #34

Comments

@morajabi
Copy link

morajabi commented Jan 17, 2023

Is this possible to do? I've seen this in Swift before.

Here it is implemented for macOS: https://medium.com/@avaidyam/building-a-better-registereventhotkey-900afd68f11f but seems to be a lot more than that lol.

@morajabi morajabi changed the title Support keydown/keyup for hotkey Support separate keydown/keyup event for hotkey Jan 17, 2023
@amrbashir
Copy link
Member

I think this maybe be possible on Linux(X11) and maybe Windows too (I have an idea but haven't tested it yet).

As for macOS, I see in the article that they are using private APIs which will result in your app getting rejected by The App Store so we can't use that. Since I am not a macOS dev, I will have to leave it to someone else to contribute.

@morajabi
Copy link
Author

morajabi commented May 16, 2023

I see in the macOS ffi impl we have kEventHotKeyPressed. Is there a reason kEventHotKeyReleased wouldn't work?
(I've seen it used in the wild: https://github.com/cocoabits/MASShortcut/pull/114/files#diff-bd9e25dca147d4385ffb9cc5e3766ae2051e1532203cebc902777a27a880e02fR21)

It is useful for creating a "hold to talk" interaction for our users. Happy to make a PR for macOS if the API is decided upon.

@amrbashir
Copy link
Member

@morajabi thanks for looking into this, the API should be straight forward, you would need to just add a field in GlobalHotKeyEvent

pub enum HotKeyState {
	Pressed,
	Released,
}

pub struct GlobalHotKeyEvent {
    /// Id of the associated [`HotKey`]
    pub id: u32,
	pub state: HotKeyState,
}

@Megamannen
Copy link

+1 on this

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 a pull request may close this issue.

3 participants