BRL.PolledInput: Functions Modinfo Source  

Polled input

The polled input module provides an easy way to detect keyboard and mouse input.

The functions in this module are only available when your program is running in Graphics mode. When working on GUI applications, you will need to use events.

Functions

Function AppSuspended()
ReturnsTrue if application is currently suspended.
DescriptionGet app suspended state.

Function AppTerminate()
ReturnsTrue if user has requested to terminate application.
DescriptionReturn app terminate state.
Example
Graphics 640,480,0

While Not AppTerminate() Or Not Confirm( "Terminate?" )

	Cls
	DrawText MouseX()+","+MouseY(),0,0
	Flip

Wend

Function FlushKeys()
DescriptionFlush key states and character queue.
InformationFlushKeys resets the state of all keys to 'off', and resets the character queue used by GetChar.

Function FlushMouse()
DescriptionFlush mouse button states.
InformationFlushMouse resets the state of all mouse buttons to 'off'.

Function GetChar()
ReturnsThe character code of the next character.
DescriptionGet next character.
InformationAs the user hits keys on the keyboard, BlitzMax records the character codes of these keystrokes into an internal 'character queue'.

GetChar removes the next character code from this queue and returns it the application.

If the character queue is empty, 0 is returned.

Function KeyDown( key )
ReturnsTrue if key is currently down.
DescriptionCheck for key state.
InformationSee 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

Function KeyHit( key )
ReturnsNumber of times key has been hit.
DescriptionCheck for key hit.
InformationThe returned value represents the number of the times key has been hit since the last call to KeyHit with the same key.

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

Function MouseDown( button )
ReturnsTrue if button is currently down.
DescriptionCheck for mouse button down state.
Informationbutton should be 1 for the left mouse button, 2 for the right mouse button or 3 for the 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

Function MouseHit( button )
ReturnsNumber of times button has been clicked.
DescriptionCheck for mouse button click.
InformationThe returned value represents the number of the times button has been clicked since the last call to MouseHit with the same button.

button should be 1 for the left mouse button, 2 for the right mouse button or 3 for the 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

Function MouseX()
ReturnsMouse x axis location.
DescriptionGet mouse x location.
InformationThe returned value is relative to the left of the 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

Function MouseY()
ReturnsMouse y axis location.
DescriptionGet mouse y location.
InformationThe returned value is relative to the top of the 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

Function MouseZ()
ReturnsMouse wheel value.
DescriptionGet mouse wheel.
InformationThe mouse wheel value increments when the mouse wheel is rolled 'away' from the user, and decrements when the mouse wheel is rolled 'towards' the user.
Example
' mousez.bmx

' prints mousez() the mousewheel position

Graphics 640,480
While Not keyhit(KEY_ESCAPE)
	cls
	drawtext "MouseZ()="+MouseZ(),0,0
	flip
Wend

Function WaitChar()
ReturnsThe character code of the pressed key.
DescriptionWait for a key press.
InformationWaitChar suspends program execution until a character is available from GetChar. This character is then returned to the application.

Function WaitKey()
ReturnsThe keycode of the pressed key.
DescriptionWait for a key press.
InformationWaitKey suspends program execution until a key has been hit. The keycode of this key is then returned to the application.

See the KeyCodes docs for a list of valid keycodes.

Function WaitMouse()
ReturnsThe clicked button.
DescriptionWait for mouse button click.
InformationWaitMouse suspends program execution until a mouse button is clicked.

WaitMouse returns 1 if the left mouse button was clicked, 2 if the right mouse button was clicked or 3 if the middle mouse button was clicked.

Module Information

Version1.01
AuthorMark Sibly, Simon Armstrong
LicenseBlitz Shared Source Code
CopyrightBlitz Research Ltd
ModserverBRL
History1.01 Release
HistoryFixed charQueue bug