I have expanded my above example. Trap task #19 may also be used to test the current state of a key. In this example the key scan code for a key is displayed only once. The program then waits for the key to be released.
Code:
*-----------------------------------------------------------
* Written by : CK
* Description : Display key code
* Note. Several function keys are predefined by the simulator
*-----------------------------------------------------------
START ORG $1000
loop
move.b #19,d0 ; read key code of last key press
clr.l d1
trap #15
move.b d1,d3 ; save key code
trap #15 ; check to see if it is currently pressed
tst.b d1 ; d1.b = 00 if key not pressed
beq loop ; wait until key press
move.b d3,d1
move.b #15,d0 ; display key code
move.b #16,d2 ; in base 16
trap #15
lea crlf,a1
move.b #14,d0 ; display newline
trap #15
keydown
move.b #19,d0 ; wait for key up
move.b d3,d1 ; restore key code
trap #15
tst.b d1 ; d1.b = $FF if key pressed
bne keydown
bra loop ; infinite loop
crlf dc.b $d,$a,0
END START