tauri-apps/global-hotkey

Detecting repeat key presses when the user is holding down a key?

Opened this issue · 5 comments

Hey folks, hope you're doing well.

At present, if a user holds down a global hotkey, this library emits a single event with state Pressed, and when the user releases the key, a single event with 'Released' is emitted. Tested on Windows 11 Pro.

However, in many cases, users may hold down a hotkey and expect it to continue firing at the rate set by the OS. Would it be possible to at least have a way to enable this behaviour please?

Thanks heaps
Fotis

It should be possible on Linux and Windows but idk about macOS, there is a lack of documentation around the APIs, the only thing I could find is https://github.com/planetbeing/xpwn/blob/ac362d4ffe4d0489a26144a1483ebf3b431da899/idevice/QuicktimeSDK/CIncludes/CarbonEvents.h#L943-L951 and it doesn't seem possible.

What is your use-case for repeated events? I believe you can simulate the repeated keys by looping until a released event.

It should be possible on Linux and Windows but idk about macOS, there is a lack of documentation around the APIs, the only thing I could find is https://github.com/planetbeing/xpwn/blob/ac362d4ffe4d0489a26144a1483ebf3b431da899/idevice/QuicktimeSDK/CIncludes/CarbonEvents.h#L943-L951 and it doesn't seem possible.

What is your use-case for repeated events? I believe you can simulate the repeated keys by looping until a released event.

Apologies for the late reply and thanks for your help. This does seem to work quite easily on Windows as you mention but indeed I have never tried such a thing on macOS.

In my case, I am registering a global hotkey for controlling the volume of an audio interface using the volume up/down keys. As you can imagine, much like Windows' native volume control, it is very common to hold volume up or down to reach the desired volume.

Presently I'm using the native Windows API calls myself but would love to use your cross-platform implementation.

We can add repeating behind a feature flag or an option on the GlobalShortcutManager but would only work on Windows and Linux. We can maybe emulate the repeating behavior on macOS but what should be the frequency?

We can add repeating behind a feature flag or an option on the GlobalShortcutManager but would only work on Windows and macOS. We can maybe emulate the repeating behavior on macOS but what should be the frequency?

On Windows, this can be configured via the OS itself:

image

So I think it optimally would be configurable for OSs that don't support it natively.

What do you think?

Cheers
Fotis

I've revisited this tonight, and while you can kinda fake this, it's not ideal. As shown above, there are settings at the OS both for the delay before repeats, and then the frequency.

You can test this on Windows yourself by say, holding down the volume up or down keys while listening to music. There's an initial delay, and then the volume changes based on the frequency you've configured continually until the key is released.

The repeats show up as events in the event loop after a call to RegisterHotKey when using the Windows SDK directly.

Cheers
Fotis