Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Program Containing All Inkey$ function codes and all other codes
#1
You're probably aware that the 12 function keys can generate 48 functions (FKey, Shift FKey, Ctrl FKey, Alt Fkey). You might be aware that there are 12 more function keys by using ALT and any of 0-9 , - , and -. You're probably not aware of some functions, like ALT-Pg Down , Shift Pg Down, beyond the usual Pg Down and Ctrl Pg Down. But did you know about ALT-Comma, and Alt-Open Brace (Actually it's available as ALT-[ and as ALT-{.)

I have created a file containing the definition for essentially every key combination recognized by Inkey$ a set of named constants. It's intended to go by most used to least used:
  • All F-Keys
  • ALT numbers
  • ALT punctuation
  • Regular upper case (Capitals)
  • Regular lower case
  • Digits
  • Punctuation
  • Control Characters

I was trying to find a file containing definitions for all key combinations that generate a 2-character Inkey$ string, and not finding one, made one myself. The program at the end will display key combinations, which is how I generated the results, as the reference in the Wiki (which I pasted in as comments at the beginning) does not show all of them.

I've attached the program so it may be downloaded.

This is what it looks like:
Code: (Select All)

'                                ASCII Keyboard Codes
'
'  Esc  F1  F2  F3  F4  F5  F6  F7  F8  F9  F10  F11  F12  Sys ScL Pause
'  27 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68  +133 +134  -  -    -
'  `~  1!  2@  3#  4$  5%  6^  7&  8*  9(  0) -_ =+ BkSp  Ins Hme PUp  NumL  /  *    -
'  126 33  64  35  36  37  94  38  42  40  41 95 43  8    +82 +71 +73    -    47  42  45
'  96 49  50  51  52  53  54  55  56  57  48 45 61
'  Tab Q  W  E  R  T  Y  U  I  O  P  [{  ]}  \|  Del End PDn  7Hme 8/?  9PU  +
'  9  81  87  69  82  84  89  85  73  79  80 123 125 124  +83 +79 +81  +71  +72  +73  43
'    113 119 101 114 116 121 117 105 111 112  91  93  92                55  56  57
'  CapL  A  S  D  F  G  H  J  K  L  ;:  '" Enter                4/?-  5  6/-?
'    -  65  83  68  70  71  72  74  75  76  58  34  13                  +75  +76  +77  E
'        97 115 100 102 103 104 106 107 108  59  39                      52  53  54  n
'  Shift  Z  X  C  V  B  N  M  ,<  .>  /?    Shift      ?        1End 2/?  3PD  t
'    *    90  88  67  86  66  78  77  60  62  63      *        +72      +79  +80  +81  e
'        122 120  99 118  98 110 109  44  46  47                          49  50  51  r
'  Ctrl Win Alt      Spacebar          Alt Win Menu Ctrl  ?-  ?  -?  0Ins    .Del
'  *    -  *          32              *  -  -    *    +75 +80 +77  +82      +83  13
'                                                                        48        46
'
'    Italics = LCase/NumLock On  * = 2 byte combo only,  + = 2 Byte: CHR$(0) + CHR$(code)
'



' Alt #
Const KeyAlt0 = Chr$(0) + Chr$(129)
Const KeyAlt1 = Chr$(0) + Chr$(120)
Const KeyAlt2 = Chr$(0) + Chr$(121)
Const KeyAlt3 = Chr$(0) + Chr$(122)
Const KeyAlt4 = Chr$(0) + Chr$(123)
Const KeyAlt5 = Chr$(0) + Chr$(124)
Const KeyAlt6 = Chr$(0) + Chr$(125)
Const KeyAlt7 = Chr$(0) + Chr$(126)
Const KeyAlt8 = Chr$(0) + Chr$(127)
Const KeyAlt9 = Chr$(0) + Chr$(128)
Const KeyAltMinus = Chr$(0) + Chr$(130)
Const KeyAltPlus = Chr$(0) + Chr$(131)

' Alt + Letter
Const KeyAltA = Chr$(0) + Chr$(30)
Const KeyAltB = Chr$(0) + Chr$(48)
Const KeyAltC = Chr$(0) + Chr$(46)
Const KeyAltD = Chr$(0) + Chr$(32)
Const KeyAltE = Chr$(0) + Chr$(18)
Const KeyAltF = Chr$(0) + Chr$(33)
Const KeyAltG = Chr$(0) + Chr$(34)
Const KeyAltH = Chr$(0) + Chr$(35)
Const KeyAltI = Chr$(0) + Chr$(23)
Const KeyAltJ = Chr$(0) + Chr$(36)
Const KeyAltK = Chr$(0) + Chr$(37)
Const KeyAltL = Chr$(0) + Chr$(38)
Const KeyAltM = Chr$(0) + Chr$(50)
Const KeyAltN = Chr$(0) + Chr$(49)
Const KeyAltO = Chr$(0) + Chr$(24)
Const KeyAltP = Chr$(0) + Chr$(25)
Const KeyAltQ = Chr$(0) + Chr$(16)
Const KeyAltR = Chr$(0) + Chr$(19)
Const KeyAltS = Chr$(0) + Chr$(31)
Const KeyAltT = Chr$(0) + Chr$(20)
Const KeyAltU = Chr$(0) + Chr$(22)
Const KeyAltV = Chr$(0) + Chr$(47)
Const KeyAltW = Chr$(0) + Chr$(17)
Const KeyAltX = Chr$(0) + Chr$(45)
Const KeyAltY = Chr$(0) + Chr$(21)
Const KeyAltZ = Chr$(0) + Chr$(44)

' Function Keys
Const KeyF1 = Chr$(0) + Chr$(59)
Const KeyF2 = Chr$(0) + Chr$(60)
Const KeyF3 = Chr$(0) + Chr$(61)
Const KeyF4 = Chr$(0) + Chr$(62)
Const KeyF5 = Chr$(0) + Chr$(63)
Const KeyF6 = Chr$(0) + Chr$(64)
Const KeyF7 = Chr$(0) + Chr$(65)
Const KeyF8 = Chr$(0) + Chr$(66)
Const KeyF9 = Chr$(0) + Chr$(67)
Const KeyF10 = Chr$(0) + Chr$(68)
Const KeyF11 = Chr$(0) + Chr$(133)
Const KeyF12 = Chr$(0) + Chr$(134)

' Function Keys - Alt
Const KeyAltF1 = Chr$(0) + Chr$(104)
Const KeyAltF2 = Chr$(0) + Chr$(105)
Const KeyAltF3 = Chr$(0) + Chr$(106)
Const KeyAltF4 = Chr$(0) + Chr$(107) ' Closes Program
Const KeyAltF5 = Chr$(0) + Chr$(108)
Const KeyAltF6 = Chr$(0) + Chr$(109)
Const KeyAltF7 = Chr$(0) + Chr$(110)
Const KeyAltF8 = Chr$(0) + Chr$(111)
Const KeyAltF9 = Chr$(0) + Chr$(112)
Const KeyAltF10 = Chr$(0) + Chr$(113)
Const KeyAltF11 = Chr$(0) + Chr$(139)
Const KeyAltF12 = Chr$(0) + Chr$(140)

' Function Keys - Ctrl
Const KeyCtrlF1 = Chr$(0) + Chr$(94)
Const KeyCtrlF2 = Chr$(0) + Chr$(95)
Const KeyCtrlF3 = Chr$(0) + Chr$(96)
Const KeyCtrlF4 = Chr$(0) + Chr$(97)
Const KeyCtrlF5 = Chr$(0) + Chr$(98)
Const KeyCtrlF6 = Chr$(0) + Chr$(99)
Const KeyCtrlF7 = Chr$(0) + Chr$(100)
Const KeyCtrlF8 = Chr$(0) + Chr$(101)
Const KeyCtrlF9 = Chr$(0) + Chr$(102)
Const KeyCtrlF10 = Chr$(0) + Chr$(103)
Const KeyCtrlF11 = Chr$(0) + Chr$(137)
Const KeyCtrlF12 = Chr$(0) + Chr$(138)

' Function Keys - Shift
Const KeyShiftF1 = Chr$(0) + Chr$(84)
Const KeyShiftF2 = Chr$(0) + Chr$(85)
Const KeyShiftF3 = Chr$(0) + Chr$(86)
Const KeyShiftF4 = Chr$(0) + Chr$(87)
Const KeyShiftF5 = Chr$(0) + Chr$(88)
Const KeyShiftF6 = Chr$(0) + Chr$(89)
Const KeyShiftF7 = Chr$(0) + Chr$(90)
Const KeyShiftF8 = Chr$(0) + Chr$(91)
Const KeyShiftF9 = Chr$(0) + Chr$(92)
Const KeyShiftF10 = Chr$(0) + Chr$(93)
Const KeyShiftF11 = Chr$(0) + Chr$(133)
Const KeyShiftF12 = Chr$(0) + Chr$(134)


' Cursor keys -
Const KeyDel = Chr$(0) + Chr$(83)
Const KeyDown = Chr$(0) + Chr$(80)
Const KeyEnd = Chr$(0) + Chr$(79)
Const KeyIns = Chr$(0) + Chr$(82)
Const KeyLeft = Chr$(0) + Chr$(75)
Const KeyPgDown = Chr$(0) + Chr$(81)
Const KeyPgUp = Chr$(0) + Chr$(73)
Const KeyRight = Chr$(0) + Chr$(77)
Const KeyUp = Chr$(0) + Chr$(72)

' Cursor keys - Alt
Const KeyAltDel = Chr$(0) + Chr$(163)
Const KeyAltDown = Chr$(0) + Chr$(160)
Const KeyAltEnd = Chr$(0) + Chr$(159)
Const KeyAltIns = Chr$(0) + Chr$(162)
Const KeyAltLeft = Chr$(0) + Chr$(157)
Const KeyAltPgDown = Chr$(0) + Chr$(161)
Const KeyAltPgUp = Chr$(0) + Chr$(153)
Const KeyAltRight = Chr$(0) + Chr$(155)
Const KeyAltUp = Chr$(0) + Chr$(152)

' Cursor keys - Ctrl
Const KeyCtrlDel = Chr$(0) + Chr$(147)
Const KeyCtrlDown = Chr$(0) + Chr$(145)
Const KeyCtrlEnd = Chr$(0) + Chr$(117)
Const KeyCtrlIns = Chr$(0) + Chr$(146)
Const KeyCtrlLeft = Chr$(0) + Chr$(115)
Const KeyCtrlPgDown = Chr$(0) + Chr$(118)
Const KeyCtrlPgUp = Chr$(0) + Chr$(132)
Const KeyCtrlRight = Chr$(0) + Chr$(116)
Const KeyCtrlUp = Chr$(0) + Chr$(141)

' Cursor keys - Shift
Const KeyShiftDel = Chr$(0) + Chr$(83)
Const KeyShiftDown = Chr$(0) + Chr$(80)
Const KeyShiftEnd = Chr$(0) + Chr$(79)
Const KeyShiftIns = Chr$(0) + Chr$(82)
Const KeyShiftLeft = Chr$(0) + Chr$(75)
Const KeyShiftPgDown = Chr$(0) + Chr$(81)
Const KeyShiftPgUp = Chr$(0) + Chr$(73)
Const KeyShiftRight = Chr$(0) + Chr$(77)
Const KeyShiftUp = Chr$(0) + Chr$(72)

'Other
Const KeyAltComma = Chr$(0) + Chr$(51)
Const KeyAltPeriod = Chr$(0) + Chr$(52)
Const KeyAltSlash = Chr$(0) + Chr$(53)
Const KeyAltSemiColon = Chr$(0) + Chr$(39)
Const KeyAltQuote = Chr$(0) + Chr$(40)
Const KeyAltOpenBracket = Chr$(0) + Chr$(26) '  [
Const KeyAltCloseBracket = Chr$(0) + Chr$(27) ' ]
Const KeyAltBackSlash = Chr$(0) + Chr$(43) '    \
Const KeyAltNumericPlus = Chr$(0) + Chr$(131) ' + on the number pad
Const KeyAltBackspace = Chr$(0) + Chr$(14)
Const KeyAltTilde = Chr$(0) + Chr$(41)

Const KeyCtrlBackspace = Chr$(0) + Chr$(147)

' Capital Letters
Const KeyCapitalA = "A"
Const KeyCapitalB = "B"
Const KeyCapitalC = "C"
Const KeyCapitalD = "D"
Const KeyCapitalE = "E"
Const KeyCapitalF = "F"
Const KeyCapitalG = "G"
Const KeyCapitalH = "H"
Const KeyCapitalI = "I"
Const KeyCapitalJ = "J"
Const KeyCapitalK = "K"
Const KeyCapitalL = "L"
Const KeyCapitalM = "M"
Const KeyCapitalN = "N"
Const KeyCapitalO = "O"
Const KeyCapitalP = "P"
Const KeyCapitalQ = "Q"
Const KeyCapitalR = "R"
Const KeyCapitalS = "S"
Const KeyCapitalT = "T"
Const KeyCapitalU = "U"
Const KeyCapitalV = "V"
Const KeyCapitalW = "W"
Const KeyCapitalX = "X"
Const KeyCapitalY = "Y"
Const KeyCapitalZ = "Z"

' Lower Case
Const KeyLowerCaseA = "a"
Const KeyLowerCaseB = "b"
Const KeyLowerCaseC = "c"
Const KeyLowerCaseD = "d"
Const KeyLowerCaseE = "e"
Const KeyLowerCaseF = "f"
Const KeyLowerCaseG = "g"
Const KeyLowerCaseH = "h"
Const KeyLowerCaseI = "i"
Const KeyLowerCaseJ = "j"
Const KeyLowerCaseK = "k"
Const KeyLowerCaseL = "l"
Const KeyLowerCaseM = "m"
Const KeyLowerCaseN = "n"
Const KeyLowerCaseO = "o"
Const KeyLowerCaseP = "p"
Const KeyLowerCaseQ = "q"
Const KeyLowerCaseR = "r"
Const KeyLowerCaseS = "s"
Const KeyLowerCaseT = "t"
Const KeyLowerCaseU = "u"
Const KeyLowerCaseV = "v"
Const KeyLowerCaseW = "w"
Const KeyLowerCaseX = "x"
Const KeyLowerCaseY = "y"
Const KeyLowerCaseZ = "z"

' Digits
Const KeyDigit0 = "0"
Const KeyDigit1 = "1"
Const KeyDigit2 = "2"
Const KeyDigit3 = "3"
Const KeyDigit4 = "4"
Const KeyDigit5 = "5"
Const KeyDigit6 = "6"
Const KeyDigit7 = "7"
Const KeyDigit8 = "8"
Const KeyDigit9 = "9"

' Punctuation
Const Dquote = Chr$(34) ' "
Const Squote = "''" '    '

Const KeyAmpersand = "&"
Const KeyAsterisk = "*"
Const KeyAt = "@"
Const KeyBackslash = "\"
Const KeyCaret = "^"
Const KeyCloseBracket = "]"
Const KeyCloseCurl = "}"
Const KeyCloseParen = ")"
Const KeyColon = ":"
Const KeyComma = ","
Const KeyDollar = "$"
Const KeyEqual = "="
Const KeyExclamation = "!"
Const KeyGreaterThan = ">"
Const KeyLessThan = "<"
Const KeyMinus = "-"
Const KeyOpenBracket = "["
Const KeyOpenCurl = "{"
Const KeyOpenParen = "("
Const KeyPercent = "%"
Const KeyPeriod = "."
Const KeyPipe = "|"
Const KeyPlus = "+"
Const KeyPound = "#"
Const KeyQuestion = "?"
Const KeySemiColon = ";"
Const KeyTick = "`"
Const KeyTilde = "~"
Const KeyUnderscore = "_"

' Control Codes
Const KeyCtrlA = Chr$(1)
Const KeyCtrlB = Chr$(2)
Const KeyCtrlC = Chr$(3)
Const KeyCtrlD = Chr$(4)
Const KeyCtrlE = Chr$(5)
Const KeyCtrlF = Chr$(6)
Const KeyCtrlG = Chr$(7)
Const KeyCtrlH = Chr$(8)
Const KeyCtrlI = Chr$(9)
Const KeyCtrlJ = Chr$(10)
Const KeyCtrlK = Chr$(11)
Const KeyCtrlL = Chr$(12)
Const KeyCtrlM = Chr$(13)
Const KeyCtrlN = Chr$(14)
Const KeyCtrlO = Chr$(15)
Const KeyCtrlP = Chr$(16)
Const KeyCtrlQ = Chr$(17)
Const KeyCtrlR = Chr$(18)
Const KeyCtrlS = Chr$(19)
Const KeyCtrlT = Chr$(20)
Const KeyCtrlU = Chr$(21)
Const KeyCtrlV = Chr$(22)
Const KeyCtrlW = Chr$(23)
Const KeyCtrlX = Chr$(24)
Const KeyCtrlY = Chr$(25)
Const KeyCtrlZ = Chr$(26)
Const KeyEscape = Chr$(27)
Const KeyFS = Chr$(28) ' File Separator
Const KeyGS = Chr$(29) ' Group Separator
Const KeyRS = Chr$(30) ' Record Separator
Const KeyUS = Chr$(31) ' Unit Separator
Const KeySpace = " "





Do
    R$ = InKey$
    If R$ <> "" Then
        Print Asc(R$, 1);
        If Len(R$) = 2 Then Print Asc(R$, 2)
    End If
Loop









Attached Files
.bas   KeyCodes.bas (Size: 10.3 KB / Downloads: 43)
While 1
   Fix Bugs
   report all bugs fixed
   receive bug report
end while
Reply
#2
I'm interested to see this, but when I try to run the code, I get an "Invalid Const" error for the Const declarations. Do I need another attached file or something? (I've downloaded the attached file)
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#3
(04-28-2024, 12:29 AM)PhilOfPerth Wrote: I'm interested to see this, but when I try to run the code, I get an "Invalid Const" error for the Const declarations. Do I need another attached file or something? (I've downloaded the attached file)

I think you are on an old version of QB64-PE or QB64. QB64-PE got CHR$ and ASC support in CONST in version 3.12.
Reply
#4
That's a really nice reference and + 1 for possting it, but...

Code: (Select All)
Const KeyShiftDel = Chr$(0) + Chr$(83)
Const KeyShiftDown = Chr$(0) + Chr$(80)
Const KeyShiftEnd = Chr$(0) + Chr$(79)
Const KeyShiftIns = Chr$(0) + Chr$(82)
Const KeyShiftLeft = Chr$(0) + Chr$(75)
Const KeyShiftPgDown = Chr$(0) + Chr$(81)
Const KeyShiftPgUp = Chr$(0) + Chr$(73)
Const KeyShiftRight = Chr$(0) + Chr$(77)
Const KeyShiftUp = Chr$(0) + Chr$(72)

That really doesn't trap the SHIFT key. In fact, don't press SHIFT and the values are exactly the same. So how can we see if either the Right SHIFT or Left SHIFT key is being held using INKEY$, or just see if SHIFT, ALT or CTRL are pressed alone or in combo? Like this...

Code: (Select All)
Do
_Limit 30
Def Seg = 0
i% = Peek(1047) Mod 16
Def Seg
b$ = InKey$
Locate 1, 1
If i% Then j% = 0
Select Case i%
Case 1: Print "Right Shift "
Case 2: Print "Left Shift "
Case 4: Print "Ctrl "
Case 5: Print "Right Shift + Ctrl "
Case 6: Print "Left Shift + Ctrl "
Case 8: Print "Alt "
Case 9: Print "Right Shift + Alt "
Case 10: Print "Left Shift + Alt "
Case 12: Print "Ctrl + Alt "
Case 13: Print "Right Shift + Ctrl + Alt"
Case 14: Print "Left Shift + Ctrl + Alt "
End Select
If Len(b$) Then
If i% = 0 Then Print Space$(24)
Locate 2, 1
End If
Select Case Len(b$)
Case 0
If Len(oldb$) Then
If Abs(z1! - Timer) > .1 Then
Locate 3, 1: Print "F12 was released. "
oldb$ = ""
End If
End If
Case 1: Print Asc(b$, 1); " ";: j% = 0
Case 2
Print "CHR$(0) +"; Asc(b$, 2); " ";
j% = Asc(Right$(b$, 1)) ' For F12 key.
If j% = 134 Then
z1! = Timer
If oldb$ <> b$ Then
Locate 3, 1: Print "F12 was pressed. "
oldb$ = b$
Sleep 1 ' Needed to prevent double entry.
Else
_Continue
End If
End If
End Select
If j% <> 134 Then Locate 3, 1: Print Space$(25);
Loop Until b$ = Chr$(27) ' End on Esc.
 

Now PEEK and POKE stuff is said to be deprecated, but I guess to preserve backwoods compatibility, they remain in use for some, but not all, of the ways they could be applied under QuickBASIC .

I love INKEY$ but it does have some problems detecting key up and down status. You would think by polling R$ = INKEY$: IF LEN(R$) THEN the key is down, but no. You can write a little sample code for yourself, hold some damn key down, hell, have an elephant sit on it, and you will find several instances in the cycle where the key is reported up, even though it was never released! This sucks big time and the only good way around it is to convert to the QB64 _KEYHIT and the up and down keywords associated with that keyboard INKEY$ replacement series. Oh, there is a Mickey Mouse method with INKEY$ that can be added, which I did include in this example using TIMER and the variable oldb$.

Now if you will excuse me, I have to hire Clippy to lean the elephant **** off my F12 key. I hear he works for peanuts!

Pete
Shoot first and shoot people who ask questions, later.
Reply
#5
(04-28-2024, 03:38 AM)a740g Wrote:
(04-28-2024, 12:29 AM)PhilOfPerth Wrote: I'm interested to see this, but when I try to run the code, I get an "Invalid Const" error for the Const declarations. Do I need another attached file or something? (I've downloaded the attached file)

I think you are on an old version of QB64-PE or QB64. QB64-PE got CHR$ and ASC support in CONST in version 3.12.
@mkilgore : Excellent work on Const! Now I can:

Code: (Select All)
Const Quote=Chr$(34)
instead of:

Code: (Select All)
Dim Shared Quote As String * 1
Quote=Chr$(34)
its been years...

Erik.
Reply




Users browsing this thread: 1 Guest(s)