Main sections
05 Input
Keyboard:
GLBasic offers 2 types of keyboard interaction.
Text Input and Key Press Checking.
Text Input...
INPUT name$, x, y;
INPUT number, x, y;
The INPUT reads in a line of text from the keyboard until the Enter key is pressed, and then stores it in a string variable or a numeric variable. The variables 'x' and 'y' sets the initial position of the input cursor. Your program will stop until the text input is complete.
Key Press Checking...
IF KEY(keycode) = 1; PRINT "KEY PRESSED", 20, 20;
Key press checking is used to see if a key is held down at that particular point. You need to query the output of 'Key(keycode)' to see whether the key corresponding to "keycode" is depressed.
To find out which keycode corresponds to which key you can use the "Keycodes" program which resides in the "Tools" menu of the GLBasic IDE.
For example...
IF KEY(57) = 1; PRINT "SPACE BAR KEY PRESSED", 20, 20;
Mouse:
MOUSESTATE mx, my, ma, mb;
MOUSESTATE returns all the current mouse parameters.
mx = The mouse cursors screen x coordinate
my = The mouse cursors screen y coordinate
ma = The button state of mouse button A (0 or 1)
mb = The button state of mouse button B (0 or 1)
e.g.
MOUSESTATE mx, my, ma, mb;
if ma = 1; PRINT "Mouse button 1 is down", 20, 20;
v=MOUSEAXIS(MouseFeature)
This command returns information about a specific feature from the mouse. This information is stored, in this case, within the variable 'v'.
To select which mouse feature you are interested in you pass an integer parameter to the MOUSEAXIS command (0 to 5 in "MouseFeature" in the above example).
So if I wanted to know if the mouse wheel was moving up or down I would use the following command :
WHILE TRUE
v=MOUSEAXIS(2)
SELECT v
CASE 0
PRINT "The mouse wheel is NOT moving", 20, 20
CASE 1
PRINT "The mouse wheel is moving UP", 20, 20
CASE -1
PRINT "The mouse wheel is moving DOWN", 20, 20
ENDSELECT
WEND
For the full list of the parameters that MOUSEAXIS accepts, please refer to the command reference.
Joystick:
JOYSTATE jx, jy, buttona, buttonb;
Gets the current joystick state and writes its state to the variables. e.g. :
// End with ESC
WHILE TRUE // Endless loop
JOYSTATE jx, jy, ba, bb
a$="JX:" + jx + " JY:" + jy + " ButtonA:" + ba + " ButtonB" +jb
PRINT a$, 10, 100
SHOWSCREEN
WEND