More keyboard input - handling hold and key repeat

In the forum post we discuss how to handle keyboard input in Storyboard, this works well for simple key press, release and repeat on a Windows OS based platform.

A new requirement came up which is to handle the case when  a key is pressed and held for a period of time then some additional logic is triggered which handles a key hold or roll-over condition - such as to increment a value.

The solution depends on which target platform OS you are using..... The reason  is that Windows targets have the standard gre.keydown, gre.keyup and also gre.keyrepeat events. However on Linux and most other platforms the OS keyboard driver does not have the concept of gre.keyrepeat, instead this is emulated by the OS driver in the form of repeated keyup and keydown events which are posted into Storyboard.

For this reason this key rollover / press-hold functionality is normally accomplished using a Storyboard timer.

I have put together an updated sample application (using SB 6.0) based on the one in the first post which illustrates this technique.

We implement a 1000ms repeating timer which is started on key down and stopped on key up. The repeating timer call back function in this case just increments a count of hold time and displays it but you can put any logic you need in this callback function.






Please sign in to leave a comment.

Didn't find what you were looking for?

New post