A timer inside another timer?

I have actually a timer and code to display images loaded from a folder. (5 seconds, but can be enlarged to 10 seconds or more).

I want to add another timer that runs inside the first one to be able to poll the keyboard and do some action depending on the key.

Is it a good idea ?

I don’t understand why you don’t want to use the same timer. Can you be more explicit on your choice to use 2 timers?

1 Like

It is very simple:

the timer loadsan image and stay as is during 5 seconds (or more). If you press a key, it will be ignored until the current “wait” time is ellapsed. This is implemented and works as I explain.
To make the above working when a key is depressed, I need to shorten the display time to the point the reader do not have time to watch the image…

Using a second timer that runs during the time the first one waits (used to poll the keyboard) would allow a responsible key (with a low value, say 50 ?).

Is it clear now ?

Why don’t you use a KeyDown/Up event on your window?

Good idea, but if I press the space bar, the idea is to stop (until another press) the timer (so the image on screen stays the same);
Left Arrow: Display the previous image
Right Arrow: Display the next image,
Top Arrow:First image / Bottom Arrow: Last image…

I have a blockage here (thus the asked help).

I don’t know what you mean by “a timer inside a timer”. I have several timers going at once, one is once a minute, another is once an hour. These are for different purposes. If you need more than one timer with different intervals, I’m not aware of any issues in doing that.

This kind of design idea comes from the ability to place a Timer object on a Window. If you look at the objects like items on the window, one might think they can put a Timer inside a Timer.

Having seen this array of timers in a project once, I despise the “just add another timer” approach to solving problems.

Usually, I have ideas. When it comes to unusually, I only have to let some days rolling (doing something else) and idea(s) comes.

In that case, none comes, so I asked here.

Maybe in some more days (a better) one will come…

It sounds like a Canvas to display the image, a KeyDown handler to control playback, and a timer to switch the image on time. The KeyDown handler can adjust the timer period or start/stop/reset it if necessary.

Edit: This forum software tries too hard sometimes. This is meant as a general reply to Emile and I was not able to clear that.

Use a KeyDown event (window, canvas, whatever) to catch the key press and adjust the timer instead of employing another timer to watch the keyboard.

1 Like

Thank you all, I will thry the KeyDown Event way.