Project

General

Profile

Differentiating initial key press from repeat code with WInteractWidget::keyWentDown()

Added by Cameron Angus over 9 years ago

Can this be done in any way? Is the information available somewhere?

To clarify, by repeat code, I mean when a signal is generated repeatedly at some frequency while a key is held down. I want to react only to the initial key press.


Replies (5)

RE: Differentiating initial key press from repeat code with WInteractWidget::keyWentDown() - Added by Wim Dumon over 9 years ago

I would recommend to use the signal keyWentDown().

Wim.

RE: Differentiating initial key press from repeat code with WInteractWidget::keyWentDown() - Added by Cameron Angus over 9 years ago

Hi Wim.

I had assumed from the name of the signal that this was indeed what I wanted. However, this signal is emitted repeatedly when a key is held down over a period of time, and as far as I can see, there is no way to determine which it was - the initial key down, or a repeat.

I guess I can keep track of a flag myself for every key of interest, but I'm not even sure if that would work properly in the case that focus is changed while a key is still being held down.

Cameron.

RE: Differentiating initial key press from repeat code with WInteractWidget::keyWentDown() - Added by Vincenzo Romano over 9 years ago

I admit yours is a weird situation.

As keys can repeat more than once and the keyWentDown() is generated by the autorepeat (this is why it's been invented), I think it's almost impossible to accurately detect autorepeats from actually typed keys without precise assistance from the client OS and hardware.

Maybe with fine-grained timing you could do it, but that should happen client-side.

RE: Differentiating initial key press from repeat code with WInteractWidget::keyWentDown() - Added by Wim Dumon over 9 years ago

Cameron,

I'm mistaken indeed. keyWentDown is also fired on auto-repeat. Maybe look for the sequence down-up-down? Not sure if this has special cases...

Best regards,

Wim.

RE: Differentiating initial key press from repeat code with WInteractWidget::keyWentDown() - Added by Cameron Angus over 9 years ago

Thanks for the feedback guys. Yep, well, shouldn't be too difficult to fudge it for my current purposes, anyway. Luckily it's not super critical.

    (1-5/5)