QBasic Tutorial 34 - Moving An Object With Arrow Keys - QB64
Description:
This tutorial will modify the code used within Tutorial 33
To use the arrow keys, we need to know the PC Keyboard Scan Codes for keyboard arrow keys.
Up Arrow - CHR$(0) + CHR$(72)
Down Arrow - CHR$(0) + CHR$(80)
Right Arrow - CHR$(0) + CHR$(77)
Left Arrow - CHR$(0) + CHR$(75)
Code Used:
DIM KeyPress AS STRING
DIM x AS INTEGER
DIM y AS INTEGER
CONST Size = 25
x = 159
y = 99
SCREEN 13
CLS
DO
KeyPress = UCASE$(INKEY$)
IF KeyPress = CHR$(0) + CHR$(72) AND y > Size THEN
CLS
y = y - 1
ELSEIF KeyPress = CHR$(0) + CHR$(80) AND y < 199 - Size THEN
CLS
y = y + 1
ELSEIF KeyPress = CHR$(0) + CHR$(75) AND x > Size THEN
CLS
x = x - 1
ELSEIF KeyPress = CHR$(0) + CHR$(77) AND x < 319 - Size THEN
CLS
x = x + 1
END IF
CIRCLE (x, y), Size, 10
LOOP UNTIL KeyPress = "Q"
Code Download: QBT34.BAS
Video Tutorial: QBasic Tutorial 34 - Moving An Object With Arrow Keys - QB64