Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trapping two keys
#13
If you want a reliable delay, don't use SLEEP. A key press interrupts SLEEP. Code SLEEP 60, run the program, and as soon as you press a key the sleep cycle is broken. _DELAT1 will always give a 1-second delay.

Another neat trick is to not delay the rest of the program at all, just delay the next key input...

Code: (Select All)
PRINT "Press any single or combo of cursor arrow keys...": PRINT
DO
    _LIMIT 30
    IF TIMER - z1 > .5 THEN
        ky = _KEYHIT
        IF ky THEN
            SELECT CASE ky
                CASE IS = 18432 ' Up-arrow
                    IF _KEYDOWN(19200) THEN
                        PRINT "Up-arrow and Left-arrow"
                    ELSEIF _KEYDOWN(19712) THEN
                        PRINT "Up-arrow and Right-arrow"
                    ELSE PRINT "Up-arrow"
                    END IF

                CASE IS = 19200 ' Left-arrow
                    IF _KEYDOWN(18432) THEN
                        PRINT "Left-arrow and Up-arrow"
                    ELSEIF _KEYDOWN(20480) THEN
                        PRINT "left-arrow and Down-arrow"
                    ELSE PRINT "Left-arrow"
                    END IF

                CASE IS = 19712 ' Right-arrow
                    IF _KEYDOWN(18432) THEN
                        PRINT "Right-arrow and Up-arrow"
                    ELSEIF _KEYDOWN(20480) THEN
                        PRINT "Right-arrow and Down-arrow"
                    ELSE PRINT "Right-arrow"
                    END IF

                CASE IS = 20480 ' Down-arrow
                    IF _KEYDOWN(19200) THEN
                        PRINT "Down-arrow and Left-arrow"
                    ELSEIF _KEYDOWN(19712) THEN
                        PRINT "Down-arrow and Right-arrow"
                    ELSE PRINT "Down-arrow"
                    END IF

            END SELECT
            _KEYCLEAR ' Remove this if you want each key pressed to register.
            z1 = TIMER
        END IF
    ELSE
        IF TIMER < z1 THEN z1 = z1 - 86400 ' Midnight adjustment.
    END IF
LOOP


I took out the CLS, so you could see the key progression. Easier to debug it that way. Lose the _KEYCLEAR if you want to peck away at the keyboard and have each key counted. If it is just about holding keys down, it's better to keep it.

My guess is you are looking for a way to move an RPG character up/down/right/left/and diagonal.

You will have to determine what, if any flags you need to set. For instance, right now a user can press three or more control keys.

Pete
Reply


Messages In This Thread
Trapping two keys - by PhilOfPerth - 10-01-2022, 01:52 AM
RE: Trapping two keys - by bplus - 10-01-2022, 01:59 AM
RE: Trapping two keys - by PhilOfPerth - 10-01-2022, 02:08 AM
RE: Trapping two keys - by bplus - 10-01-2022, 02:26 AM
RE: Trapping two keys - by Pete - 10-01-2022, 02:38 AM
RE: Trapping two keys - by PhilOfPerth - 10-01-2022, 08:05 AM
RE: Trapping two keys - by Pete - 10-01-2022, 01:07 PM
RE: Trapping two keys - by bplus - 10-01-2022, 03:33 PM
RE: Trapping two keys - by Pete - 10-01-2022, 04:19 PM
RE: Trapping two keys - by PhilOfPerth - 10-01-2022, 11:24 PM
RE: Trapping two keys - by PhilOfPerth - 10-02-2022, 12:04 AM
RE: Trapping two keys - by bplus - 10-02-2022, 01:41 AM
RE: Trapping two keys - by Pete - 10-02-2022, 02:00 AM
RE: Trapping two keys - by PhilOfPerth - 10-02-2022, 02:34 AM
RE: Trapping two keys - by bplus - 10-02-2022, 05:20 PM
RE: Trapping two keys - by mnrvovrfc - 10-02-2022, 07:51 PM
RE: Trapping two keys - by Pete - 10-02-2022, 05:51 PM
RE: Trapping two keys - by James D Jarvis - 10-02-2022, 07:56 PM
RE: Trapping two keys - by bplus - 10-02-2022, 07:58 PM



Users browsing this thread: 6 Guest(s)