C ++ / Qt. If you press and hold a button on the keyboard, for example, key_left , an event is sent to the corresponding widget, then there is a delay of about a second, and then sending the events again while the button is pressed. Can you tell me how to remove this delay and how to adjust the delays between the event events when the button is pressed?

    2 answers 2

    Try changing ( keyboardInputInterval ) on the global QApplication instance (for example, via the qApp macro).
    From the documentation:

    This property makes it possible to distinguish a key press from two consecutive key presses. The default value on X11 is 400 milliseconds. On Windows and Mac OS, the operating system's value is used. This property was introduced in Qt 4.2.

    You can also try using qApp->processEvents() to push the message queue.

    • I tried, it's not that. keyboardInputInterval is the interval between two successive keystrokes (press release, press release). And when the button was pressed and held once, then the push and release events are sent as well. I need an interval between these events. - nicolai

    In Qt, there is no way out of the box to change the intervals of those system events from the keyboard that interest you. You will have to emulate this behavior manually. First you have to override the protected methods of pressing and releasing the key. They will need to track when the button was pressed, but was not released for some minimum time interval. As soon as this state is captured, you start generating your own events (just create and send the corresponding objects) of pressing the key at the desired custom interval.

    Note that sending your own events needs to be done through a queue ( QCoreApplication::postEvent() ), because otherwise you risk getting endless recursion.

    You also need some kind of custom flag to distinguish system events from your own, since the latter will also fall into the corresponding event handlers of the widget.