GETKEY error

New to FreeBASIC? Post your questions here.
Post Reply
Triopstor
Posts: 113
Joined: Apr 25, 2006 13:11

GETKEY error

Post by Triopstor »

I have a GETKEY loop that works well but I want to add to it. The code so far is:

Code: Select all

 DO 
   X5=GETKEY
 LOOP UNTIL X5=13 OR X5=32 OR X5=27
This will loop until ESC/SPACE/ENTER key is pressed how do I modify this to include:

TAB KEY GETKEY=9
F1 KEY GETKEY=15359

When I try for "LOOP UNITIL X5=13 OR X5=32 OR X5=15359" FreeBASIC gives me an error of "Error Encountered - Unknown Key" for the F1 Key. I don't get it?

Code: Select all

DO
        X5=GETKEY
        'PRINT X5
LOOP UNTIL X5=13 OR X5=32 OR X5=15359
The above code doesn't work for the F1 keyboard key?
BasicCoder2
Posts: 3917
Joined: Jan 01, 2009 7:03
Location: Australia

Re: GETKEY error

Post by BasicCoder2 »

@Triopstor

Probably need to read up the FreeBasic manual on GETKEY?
https://www.freebasic.net/wiki/FBWiki

This works for me with Windows11

Code: Select all

dim as integer keyCode

DO
        keyCode = GETKEY
        print keyCode;

LOOP UNTIL keyCode =13 OR keyCode =32 OR keyCode = 15359

Triopstor
Posts: 113
Joined: Apr 25, 2006 13:11

Re: GETKEY error

Post by Triopstor »

BasicCoder2 wrote: May 03, 2024 4:34 @Triopstor

Probably need to read up the FreeBasic manual on GETKEY?
https://www.freebasic.net/wiki/FBWiki

This works for me with Windows11

Code: Select all

dim as integer keyCode

DO
        keyCode = GETKEY
        print keyCode;

LOOP UNTIL keyCode =13 OR keyCode =32 OR keyCode = 15359

Thank you for responding BasicCoder2. Yes I do need to read a manual such as the one you suggested. And I do look at the help that comes with the Editor.

But for some reason I get unusual problems. The code is similar to mine. I have a dim statement as

Code: Select all

DIM SHARED as Integer X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11
but this doesn't explain the "Error Encountered - Unknown Key" response from my computer.

Thanks Again BasicCoder2.
BasicCoder2
Posts: 3917
Joined: Jan 01, 2009 7:03
Location: Australia

Re: GETKEY error

Post by BasicCoder2 »

@Triopstor
...but this doesn't explain the "Error Encountered - Unknown Key" response from my computer.

Got me there! I don't know why it works of my computer (and I guess type of keyboard?) and not on yours.

I have found it visually useful to print out the numbers in hex when wanting to know the numbers returned by a keypress.

Code: Select all

dim as integer keyCode

DO
        keyCode = GETKEY
        print hex(keyCode,4)

LOOP UNTIL keyCode = 13

Post Reply