EASy68K
http://www.easy68k.com/EASy68Kforum/

key press and multiple keys
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=5&t=1206
Page 1 of 1

Author:  RetroRich [ Wed Jun 26, 2013 11:40 pm ]
Post subject:  key press and multiple keys

Hi,

So I'm using the following code to see which key was pressed

Code:
* -- grab input --
    *Check to see if a key has been pressed
       clr.l   d1
       move.b   #7,d0
       trap   #15
       tst.l   d1
       beq       nokey       Key wasn't pressed, clear movement

    *Read the key that was pressed and find out which key it was
       move.b   #5,d0
       trap   #15


then comparing the d1 register e.g.:

Code:
       cmp.b   #'4',d1       Key pressed: 4 (left)
       beq       move_left


OK that's all fine, however if I press a key down and hold, it detects the key press, but then it's almost like it clears the d1 for a second or so and then registers it again.

Next issue is that if I press and hold a key, then press another key, the first key is no longer registering, even though it's still being pressed.

Is this correct? Am I using the correct method for detecting key presses? Or should I be using a better way of detecting multiple key presses?

Any help on the matter would be much appreciated, thank you, Rich

Author:  profkelly [ Thu Jun 27, 2013 12:09 pm ]
Post subject:  Re: key press and multiple keys

Trap task 7 does character input. The auto key repeat feature in Windows will make it look like the key is being pressed and released if a key is held down. To read the current state of a key use trap task 19. Up to 4 key states may be read at the same time. From EASy68K help:
    Returns current state of up to 4 specified keys or returns key scan code.
    Pre: D1.L = four 1-byte key codes
    Post: D1.L contains four 1-byte Booleans.
    $FF = corresponding key is pressed, $00 = corresponding key not pressed.
    Pre: D1.L = $00000000
    Post: D1.L upper word contains key code of last key up.
    D1.L lower word contains key code of last key down.

    Example:
    Code:
         MOVE.B #19,D0     
         MOVE.L #'A'<<24+'S'<<16+'D'<<8+'F',D1 ; check for keypress (a,s,d,f)
         TRAP   #15
         BTST.L #24,D1     ; test for 'a'
         IF <NE> THEN      ; if 'a'
             {a code}
         ENDI
         BTST.L #16,D1     ; test for 's'
         IF <NE> THEN      ; if 's'
            ... etc

Author:  RetroRich [ Thu Jun 27, 2013 1:11 pm ]
Post subject:  Re: key press and multiple keys

Thank you so much, that is now perfect! I thought it was task 19 I needed, but I couldn't work out how to use it, but it's working great now.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/