Page 1 of 1

ESC key on CPC

Posted: Fri Jan 24, 2025 6:17 am
by ervin
Hi there.

Is there a way to check the key state of the ESC key on the Amstrad CPC target?
I need to find a way to go back to the main menu of my program from within the game.

Thanks.

Re: ESC key on CPC

Posted: Fri Jan 24, 2025 12:02 pm
by spotlessmind1975
Hi ervin, nice to read you! :D
ervin wrote: Fri Jan 24, 2025 6:17 am Is there a way to check the key state of the ESC key on the Amstrad CPC target?
You could check for any value that come from SCANCODE, and use it in KEY STATE.
Take, for example, this code:

Code: Select all

DO
    PRINT SCANCODE
LOOP
If you run it, it will print a series of 255 (which is the equivalent of "no keys pressed"). If you press the ESC key on the Amstrad keyboard, it will print the number 66. That number can be used with this program:

Code: Select all

DO
    IF KEY STATE(66) THEN
       PRINT "GO TO MAIN MENU"
    ENDIF
LOOP
ervin wrote: Fri Jan 24, 2025 6:17 am I need to find a way to go back to the main menu of my program from within the game.
You could place control with the KEY STATE statement anywhere in your program, but the best place is definitely in a game loop, where you can periodically check the pressure.

Re: ESC key on CPC

Posted: Fri Jan 24, 2025 12:09 pm
by ervin
PERFECT!!!
Thanks so much.