REALbasic – Timer Class line

Timer Class is a object that can execute a code after a specified period of time or at a repeated interval. If added to a window via the Window Editor, it is not visible in the built application since it is not a control. Learn how can you use it!

What can we do with Timer Class?

The answer for this question is very easy – everything we like. For example we can use it for closing our application after 10 minutes from start, we can monitor some changes (keydown events, files changes), count time and speaking in one word one more time executing some code after a specified period of time (Period: 1000 = 1 second) .

Shutdown application after 10 seconds

Add to Window1 a Timer Class from Control Tab and set the Period Property to 10 000. Change also the Mode to 1- Single (this will start only once the Timer). Double click on Timer Control (Timer Sub Action()) and enter there:

1
Quit

Keydown events

The following code in the Action event of a Timer detects whether the Up, Down, Left, or Right arrow keys are pressed and display you a info in StaticText1 Control. Please remember to change the Mode Property to 2 – Multiple and the Period to for example 10.

1
2
3
4
5
6
7
8
9
10
11
12
if Keyboard.AsyncKeyDown(123) then
StaticText1.Text = "you have pressed left arrow key"
end if
if Keyboard.AsyncKeyDown(124) then
StaticText1.Text = "you have pressed right arrow key"
end if
if Keyboard.AsyncKeyDown(125) then
StaticText1.Text = "you have pressed down arrow key"
end if
if Keyboard.AsyncKeyDown(126) then
StaticText1.Text = "you have pressed up arrow key"
end if

Author: Jakub Pawlak

I'm interested in all. Currently working on the development of TUTSPOLIS and I hope that in near feature the project will be successful.

Leave a Reply

Copyrights (c) TUTSPOLIS | Powered by Wordpress MU | Inspired at Elegant Themes designed by qbap (HTML5 & CSS3)