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!
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) .
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 |
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 |