CONST kbSeg = &h40 ' Memory segment of keyboard buffer CONST kbHead = &h1A ' Memory offset to keyboard buffer's head CONST kbTail = &h1C ' Memory offset to keyboard buffer's tail DIM keyStroke(0 to 127) AS INTEGER ' Status of all keys DIM keyStat AS INTEGER ' Last key status DIM keyPressed AS INTEGER ' Last key status - is pressed DIM keyScanCode AS INTEGER ' Last key status - scan code DO keyStat = INP(&h60) ' Read the last key status change on port 0x60 keyPressed = keyStat < 128 ' Value is at least 128 if bit 7 (released) is set keyScanCode = keyStat AND &h7F ' Masking bits 0-6 to obtain scan code keyStroke(keyScanCode) = keyPressed ' Store key status for later use DEF SEG = kbSeg ' Set current memory segment to 0x40 POKE kbHead, PEEK(kbTail) ' Apply tail value to head (erase key buffer) DEF SEG ' Reset to default memory segment LOCATE 1 FOR i% = 0 TO 127 ' Loop through keyStroke() elements PRINT keyStroke(i%); ' Display status of key with scan code i% IF (((i% + 1) AND 15) = 0) THEN ' If we've displayed 16 scan codes, PRINT ' Get another line END IF NEXT i% LOOP UNTIL keyStroke(1) ' Loop until ESCAPE (scan code 1) is pressed