ESC key on CPC

This forum is dedicated to those who want support programming in ugBASIC.
Questo forum è dedicato a chi desidera supporto per programmare in ugBASIC.
Ce forum est dédié à ceux qui souhaitent prendre en charge la programmation en ugBASIC.
Post Reply
ervin
Posts: 5
Joined: Wed Jul 03, 2024 12:41 pm

ESC key on CPC

Post 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.
spotlessmind1975
Site Admin
Posts: 191
Joined: Fri Oct 06, 2023 8:25 pm

Re: ESC key on CPC

Post 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.
ervin
Posts: 5
Joined: Wed Jul 03, 2024 12:41 pm

Re: ESC key on CPC

Post by ervin »

PERFECT!!!
Thanks so much.
Post Reply