System

The BlitzMax System module contains commands for controlling System timers, displaying system requesters, retrieving the system time and date and various commands for receiving keyboard and mouse status.

CurrentDate and CurrentTime return the system date and time respectively.

Delay pauses program executions for a specified amount of time while MilliSecs reports the system time. CreateTimer and WaitTimer provide functions for executing code based on user timers.

Notify, Confirm, Proceed and RequestFile provide functions for using standard system requesters when requiring information from users.

KeyHit, KeyDown, MouseX, MouseY, MouseZ, MouseHit, MouseDown, WaitKey, WaitMouse and MoveMouse all provide functions for examining the state of the keyboard and mouse devices connected to the system. See the FreeJoy module for providing joystick support in BlitzMax programs.

Function reference

CurrentDate$()   Returns the current date in the format: DD MON YYYY (i.e. 10 DEC 2000).

Example:

' currentdate.bmx

Print "The date is "+CurrentDate$()

CurrentTime$()   Returns the current time in the format: HH:MM:SS (i.e. 14:31:57).

Example:

' currenttime.bmx

Print "The time is "+CurrentTime$()

Delay( millis )   Waits a given number of milliseconds.

Example:

Rem
The following BlitzMax program prints a New line To the console 10 times a second.
End Rem

' testtimer.bmx

For i=1 To 10
	Print frame
	frame:+1
	Delay 100
Next

MilliSecs()   The number of milliseconds since system startup.

Example:

Rem
MilliSecs is useful For seeding the random number generator.
End Rem

SeedRnd(MilliSecs())

For i=1 To 10
	Print Rnd()
Next

CreateTimer:TSyncTimer( hertz# )   Creates a timer with a period of hertz#

Example:

Rem
The following BlitzMax program prints a New line To the console 5 times a second.
End Rem

' testtimer.bmx

t=CreateTimer(5)
frame=0

For i=1 To 10
	WaitTimer(t)
	Print frame
	frame:+1
Next

WaitTimer( timer:TSyncTimer )   Waits for a timer to trigger.

Example:

Rem
 WaitTimer( timer:TSyncTimer )
Waits For a timer To trigger.
End Rem

Notify( text$,serious=False )   Notifies the user and waits for an OK to proceed.

Example:

' notify.bmx

Notify "Hello World"

Confirm( text$,serious=False )   Displays a message and waits for the user to select YES or NO.

Returns:
1 - YES
0 - NO

Example:

' confirm.bmx

result=Confirm("Are you sure?")

Print result

Proceed( text$,serious=False )   Displays a message and waits for the user to select either YES, NO or CANCEL.

Returns:
1 - YES
0 - NO
-1 - CANCEL

Example:

' proceed.bmx

result=Proceed("Are you sure you want to continue?")

Print result

RequestFile$( text$,extensions$="",save_flag=False,default_path$="" )   Displays a system file requester.

text - used as the title of the file requester
extensions$ - optional list of file extensions to display
save_flag - true for save style, false for load style
default_path - the default initial path for the file requester

Example:

' requestfile.bmx

filename$=RequestFile( "Select graphic file to open","png,jpg,bmp" )

Print filename

KeyHit( keycode )   Check for key hit

Returns: Number of times key has been hit.

KeyHit also resets the count for the key specified to zero.
See the KeyCodes docs for a list of valid keycodes.

Example:

' keyhit.bmx

' the following code draws a circle every time the
' program detects the spacebar has been pressed
' and exits when it detects the ESCAPE key has
' been pressed

Graphics 640,480
While Not KeyHit(KEY_ESCAPE)
	Cls
	If KeyHit(KEY_SPACE) DrawOval 0,0,640,480
	Flip
Wend

KeyDown( keycode )   Check for key down state

Returns: True if key is currently down.
See the KeyCodes docs for a list of valid keycodes.

Example:

' keydown.bmx

' the following code draws a circle if the
' program detects the spacebar is pressed
' and exits when it detects the ESCAPE key has
' been pressed

Graphics 640,480
While Not KeyHit(KEY_ESCAPE)
	Cls
	If KeyDown(KEY_SPACE) DrawOval 0,0,640,480
	Flip
Wend

FlushKeys()   Flush the BlitzMax keyboard and mousebutton buffers

Any keys pressed by the user will no longer report True with KeyHit, KeyDown, MouseHit and MouseDown until pressed again.


MouseX()   Get mouse x location

Returns: Mouse x axis location, relative to top-left of screen

Example:

' mousex.bmx

' the following tracks the position of the mouse

Graphics 640,480
While Not KeyHit(KEY_ESCAPE)
	Cls
	DrawOval MouseX()-10,MouseY()-10,20,20
	Flip
Wend

MouseY()   Get mouse y location

Returns: Mouse y axis location, relative to top-left of screen

Example:

' mousey.bmx

' the following tracks the position of the mouse

Graphics 640,480
While Not KeyHit(KEY_ESCAPE)
	Cls
	DrawRect MouseX()-10,MouseY()-10,20,20
	Flip
Wend

MouseZ()   Get mouse wheel

Returns: Mouse wheel value

Example:

' mousez.bmx

' prints mousez() the mousewheel position

Graphics 640,480
While Not KeyHit(KEY_ESCAPE)
	Cls
	DrawText "MouseZ()="+MouseZ(),0,0
	Flip
Wend

MouseHit( button )   Check for a mouse button hit

Returns: Number of times mouse button has been hit

MouseHit resets the count for the button specified to zero.
button can be one of the following values:
1 - Left Mouse Button
2 - Right Mouse Button
3 - Middle Mouse Button

Example:

' mousehit.bmx

Graphics 640,480

While Not KeyHit(KEY_ESCAPE)
	Cls
	If MouseHit(1) DrawRect 0,0,200,200
	If MouseHit(2) DrawRect 200,0,200,200
	If MouseHit(3) DrawRect 400,0,200,200
	Flip
Wend

MouseDown( button )   Check for mouse button down state

Returns: True if mouse button is currently down

button can be one of the following values:
1 - Left Mouse Button
2 - Right Mouse Button
3 - Middle Mouse Button

Example:

' mousedown.bmx

Graphics 640,480

While Not KeyHit(KEY_ESCAPE)
	Cls
	If MouseDown(1) DrawRect 0,0,200,200
	If MouseDown(2) DrawRect 200,0,200,200
	If MouseDown(3) DrawRect 400,0,200,200
	Flip
Wend

WaitKey()   Wait for a key press

WaitMouse()   Wait for a mousebutton press

MoveMouse(x,y)   Position the mouse cursor at a specific location on the screen.

Example:

' movemouse.bmx

' demonstrates using the mouse as a proportional controller
' by locking the mouse to the center of the screen and reporting
' MouseXSpeed and MouseYSpeed variables 

Global MouseXSpeed,MouseYSpeed

Function SampleMouse()
	MouseXSpeed=MouseX()-320
	MouseYSpeed=MouseY()-240
	MoveMouse 320,240
End Function

Graphics 640,480

HideMouse
MoveMouse 320,240

While Not KeyHit(KEY_ESCAPE)
	SampleMouse
	Cls
	DrawText "MouseXSpeed="+MouseXSpeed,0,0
	DrawText "MouseYSpeed="+MouseYSpeed,0,20
	Flip
Wend

Module Information

Modulebrl.system
Version 1.00
Author Mark Sibly
License Blitz Shared Source Code
Copyright Blitz Research Ltd
Modserver BRL