1

How can I stop the KeyRelease event being spammed when I hold down a key on the keyboard?

I've searched the internet and found people suggesting putting a timer in the loop but I want a more efficient way.

Isn't there something in X11 that can turn the autorepeat off?

  • You probably can, try playing with the command `xset r rate ` – Jo So Oct 09 '16 at 02:51
  • But as always: Why would you want to do that? – Jo So Oct 09 '16 at 02:52
  • no I want to turn autorepeat off just for the program, I'm creating a cross platform applicatian and i'm looking for a piece of code that will turn the autorepeat off on that application's window for anyone who starts the application – Luka Jankovic Oct 09 '16 at 02:58
  • Why do you think your users would be happy with this? I for one will uninstall such application the moment it does this. It's **MY** keyboard. – n. m. could be an AI Oct 09 '16 at 21:12
  • The application doesn't change anything to your keyboard. Before the user presses a key the function XAutoRepeatOff is called and when the person is done XAutoRepeatOn is called so you're back to normal. – Luka Jankovic Oct 09 '16 at 21:50
  • 1
    "The application doesn't change anything to your keyboard" Sure it does, it switches the autorepeat on. If it plans to switch it back on, that's very good, but plans don't always work. There are many less intrusive ways to cope with the situation, see e.g. [this Q&A](http://stackoverflow.com/questions/2100654/ignore-auto-repeat-in-x11-applications). – n. m. could be an AI Oct 10 '16 at 10:32

2 Answers2

4

I found the solution, I can use

XAutoRepeatOff(Display* display);
4

XAutoRepeatOff turns off auto-repeat for all applications.

To disable auto-repeat of KeyRelease events just for your application, use XkbSetDetectableAutorepeat as discussed in Ignore auto repeat in X11 applications.

Community
  • 1
  • 1
alanc
  • 4,102
  • 21
  • 24