PEEK

From QB64 Wiki
Revision as of 01:55, 7 October 2009 by 90.231.62.232 (talk)
Jump to navigation Jump to search

The PEEK function returns the value that is contained at a certain memory address.


Syntax: variable = PEEK(address)


  • Use DEF SEG before PEEK to specify which segment to work in.
  • PEEK only reads the memory byte value. Not certain bits.
  • To return to Basic default segment use DEF SEG without any arguments.


Example: Checking the 8 keyboard bit settings using a PEEK return value.


DEF SEG = 0 ' BIOS area
oldvalue = PEEK(1047) ' initial setting saved to reset later
DO: port = PEEK(1047)
IF port > 0 THEN LOCATE 26, 19: COLOR 11: PRINT "Turn ALL Locks off to see each key's bit value!"
COLOR 14:LOCATE 2, 25: PRINT "PEEK(1047) ="; port; "present keyboard port byte value"
LOCATE 5, 35
IF (port AND 1) = 1 THEN COLOR 10: PRINT "R SHIFT PRESSED  " ELSE COLOR 12: PRINT "R SHIFT RELEASED"
LOCATE 7, 35
IF (port AND 2) = 2 THEN COLOR 10: PRINT "L SHIFT PRESSED  " ELSE COLOR 12: PRINT "L SHIFT RELEASED"
LOCATE 9, 35
IF (port AND 4) = 4 THEN COLOR 10: PRINT "CTRL KEY PRESSED " ELSE COLOR 12: PRINT "CTRL KEY RELEASED"
LOCATE 11, 35
IF (port AND 8) = 8 THEN COLOR 10: PRINT "ALT KEY PRESSED " ELSE COLOR 12: PRINT "ALT KEY RELEASED"
LOCATE 13, 35
IF (port AND 16) = 16 THEN COLOR 10: PRINT "SCROLL LOCK ON " ELSE COLOR 12: PRINT "SCROLL LOCK OFF"
LOCATE 15, 35
IF (port AND 32) = 32 THEN COLOR 10: PRINT "NUMBER LOCK ON " ELSE COLOR 12: PRINT "NUMBER LOCK OFF"
LOCATE 17, 35
IF (port AND 64) = 64 THEN COLOR 10: PRINT "CAPS LOCK ON " ELSE COLOR 12: PRINT "CAPS LOCK OFF"
LOCATE 19, 35
IF (port AND 128) = 128 THEN COLOR 10: PRINT "INSERT MODE ON " ELSE COLOR 12: PRINT "INSERT MODE OFF"
COLOR 11: LOCATE 21, 20: PRINT "Press mode keys to change or [ESC] to quit!";
LOOP UNTIL INP(&H60) = 1 ' escape key exit
POKE 1047, oldvalue ' reset to original settings
DEF SEG


See also: POKE, INP, AND, VARSEG, VARPTR, Scancodes(demo)


Navigation:

Go to Keyword Reference - Alphabetical

Go to Keyword Reference - By usage