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

Any way to prevent repeating commands? #156

Open
ghost opened this issue Oct 7, 2019 · 7 comments · May be fixed by #308
Open

Any way to prevent repeating commands? #156

ghost opened this issue Oct 7, 2019 · 7 comments · May be fixed by #308

Comments

@ghost
Copy link

ghost commented Oct 7, 2019

Is there any way to prevent the command to keep being repeated when I am holding a key, so when I press the keys but keep holding them, it only executes the command once?

Edit: I tried adding @ at the beginning of the keysym and as far as I can tell, it didn't produce any effect.

@alexherbo2
Copy link

Nope. Key-bindings are executed on key-down. It could be possible with a key-press or key-up method, or with a repeat parameter which tells whether the key combination is being held down.

https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat

@dicktyr
Copy link

dicktyr commented Feb 24, 2020

from the manual

If @ is added at the beginning of the keysym, the command will be run on key release events, otherwise on key press events.

@ghost
Copy link
Author

ghost commented Feb 25, 2020

from the manual

If @ is added at the beginning of the keysym, the command will be run on key release events, otherwise on key press events.

Sorry, I forgot to mention that I had already tried that and it didn't produce any different result from the default (as far as I can tell).

@smeikx
Copy link

smeikx commented Jun 2, 2020

If this is still an issue, could you share the snippet in question?

Prefixing @ should really do the trick, maybe there is a problem with the command you want to execute.

@ghost
Copy link
Author

ghost commented Jun 3, 2020

I am not sure @ is what I need, maybe I didn't explain the issue correctly.

I am using st as my main terminal emulator and whenever I want to open it I do super + Return, however if I keep the keysym pressed long enough, it will keep opening up new terminals. I am trying to avoid that behaviour.

@smeikx
Copy link

smeikx commented Jun 4, 2020

No, you did explain it perfectly well. I tried it myself and came to the same result as you did.

super + @Return
    st

This would work if keeping a key pressed would result in multiple KeyPress events but only in a single, final KeyRelease event. Using xev -event keyboard I determined that this is not the case; instead, every KeyPress is accompanied by a KeyRelease.

Unfortunately, it doesn’t seem possible to make sxhkd react only to the final KeyRelease event.

My conclusion: No, you cannot accomplish what you want using sxhkd only.

You could maybe achieve something similar using chords, though.
Otherwise you would probably have to tinker with your keyboard settings or use a script involving a timer tuned to the typematic rate. But I doubt it would be worth the effort.

@deraffe
Copy link

deraffe commented Jun 10, 2020

@smeikx There seems to be a way to detect autorepeating keys using the XCB equivalent of XkbSetDetectableAutoRepeat, see https://stackoverflow.com/a/41403168

You could then expose this in sxhkd by providing a modifier that executes a command only once per key{press,release}.

@brenopacheco brenopacheco linked a pull request Jul 22, 2023 that will close this issue
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.

4 participants