More Inkey() console fun

Everything else that doesn't fall into one of the other PB categories.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.

Ignore this, I think I figured out what it was (the shift keycode distinguishes between the normal keys and the keypad versions). But you might find my ramblings useful in case you come up against it.

----------
Is there any particular reason that when using Inkey() and pressing an arrow key you get the following:

Chr(224)+Chr(x) ; where x is the keycode
Chr(255)+Chr(42) ; This is the code for the left shift key?

Now I know about the extended characters using 2 keys and so on. But why the double character when pressing the cursor keys? And why is the second one the same as the left shift? And does ASCII code 224 represent something mystical?

Update: The Insert, Home, Page Up, Delete, End and Page down keys also have this behaviour. However, with numlock turned off the keypad versions of those keys do not have the double keycode. So I'm guessing thats it.

I've tried various searches on the net but haven't come up with anything.

This is the code I'm using:

Code: Select all

If OpenConsole()
    PrintN("Press Escape to exit")

    Repeat
        key_pressed$ = Inkey()
        
        If key_pressed$""
            ; Show the key if it has a printable ASCII code
            If Asc(key_pressed$)>=32 And Asc(key_pressed$)<128
                PrintN("You pressed: "+Left(key_pressed$, 1))
                PrintN("It has a raw code of: "+Str(PeekB(@key_pressed$+1) & $FF))
            Else
                ; Either a non-printable ASCII code or an extended character
                PrintN("The key you pressed has raw values of: "+Str(PeekB(@key_pressed$) & $FF)+" and "+Str(PeekB(@key_pressed$+1) & $FF))
            EndIf
        EndIf
        
    ; Wait until escape is pressed
    Until Left(key_pressed$, 1) = Chr(27)

    CloseConsole()
EndIf
End
Thanks for your input.


--
I used to be a nihilist but I don't believe in that any more.
(Win98first ed. + all updates, PB3.51, Ed3.53)