ON STRIG(n)
From QB64 Wiki
The ON STRIG(n) statement is an event procedure that directs program flow upon the press of a specified joystick button.
- ON STRIG(button_function) GOSUB {linenumber|linelabel}
QB64 Syntax:
- ON STRIG(button_function[, joystick_number]) {GOSUB {linelabel|linenumber}|sub-procedure}
- In QB64 the value can be any button function number with any number of joysticks. See STRIG and STICK for parameters.
- In Qbasic, value of n can be a number from 0 to 3 only as it can only monitor 2 joystick buttons and 2 joysticks.
- There are two button functions for each button. The even numbered function is always the event of any press since last read.
- The statement sends the procedure to a line number, SUB or GOSUB procedure or line number when a button event occurs.
Example 1: Reading a STRIG event to do something in a GOSUB procedure.
ON STRIG(0) GOSUB 10 STRIG(0)ON DO PRINT "."; _LIMIT 30 LOOP UNTIL INKEY$ <> "" END 10 a$ = "[STRIG 0 EVENT]" FOR x = 1 TO LEN(a$) PRINT MID$(a$, x, 1); _DELAY 0.02 NEXT RETURN
Example 2: Displays any number of game pad or joystick device button presses.
FOR j = 1 TO 256 FOR b = 1 TO 256 ON STRIG((b - 1) * 4, j) JoyButton (j - 1) * 256 + b - 1 NEXT NEXT STRIG ON DO PRINT "."; _LIMIT 30 LOOP UNTIL INKEY$ <> "" END SUB JoyButton (js AS LONG) PRINT "Joystick #"; js \ 256 + 1; "button #"; (js AND 255) + 1; "pressed!" END SUB
- Explanation: Up to 256 controllers can be used in QB64 with many buttons to read.
See also:
- STRIG , STICK (functions)
- STRIG(n) (statement)
- _DEVICES, _DEVICE$, _LASTBUTTON
- Single and Dual Stick Controllers