GetKeycode() keycodes for Inkey.

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

GetKeycode() keycodes for Inkey.

Post by D.J.Peters »

GetKeyCode() with Inkey()

Joshy

Code: Select all

enum KEYCODES
  K_NONE             =   0
  CTRL_A             =   1
  CTRL_B             =   2
  CTRL_C             =   3
  CTRL_D             =   4
  CTRL_E             =   5
  CTRL_F             =   6
  K_BELL             =   7
  K_BACKSPACE        =   8
  K_TAB              =   9
  CTRL_J             =  10
  CTRL_K             =  11
  CTRL_L             =  12
  K_ENTER            =  13
  CTRL_N             =  14
  CTRL_O             =  15
  CTRL_P             =  16
  CTRL_Q             =  17
  CTRL_R             =  18
  CTRL_S             =  19
  CTRL_T             =  20
  CTRL_U             =  21
  CTRL_V             =  22
  CTRL_W             =  23
  CTRL_X             =  24
  CTRL_Y             =  25
  CTRL_Z             =  26
  K_ESCAPE           =  27
  CTRL_5             =  29
  CTRL_6             =  30
  CTRL_7             =  31
  K_SPACE            =  32
  K_EXCLATIONMARK    =  33 ' !
  K_QUOTE            =  34 ' "
  K_HASH             =  35 ' #
  K_DOLLAR           =  36 ' $
  K_PERCENT          =  37 ' %
  K_AMPERSAND        =  38 ' &
  K_SINGLEQUOTE      =  39 ' '
  K_LEFTBRACKET      =  40 ' (
  K_RIGHTBRACKET     =  41 ' )
  K_MULTIPLY         =  42 ' *
  K_PLUS             =  43 ' +
  K_COMMA            =  44 ' ,
  K_MINUS            =  45 ' -
  K_PERIOD           =  46 ' .
  K_SLASH            =  47 ' /
  K_0                =  48
  K_1                =  49
  K_2                =  50
  K_3                =  51
  K_4                =  52
  K_5                =  53
  K_6                =  54
  K_7                =  55
  K_8                =  56
  K_9                =  57
  K_COLON            =  58 ' :
  K_SEMICOLON        =  59 ' ;
  K_LESS             =  60 ' <
  K_EQUALS           =  61 '  =
  K_GREATER          =  62 ' >
  SHIFT_QUESTIONMARK =  63 ' ?
  AltGr_Q            =  64 ' @
  SHIFT_A            =  65
  SHIFT_B            =  66
  SHIFT_C            =  67
  SHIFT_D            =  68
  SHIFT_E            =  69
  SHIFT_F            =  70
  SHIFT_G            =  71
  SHIFT_H            =  72
  SHIFT_I            =  73
  SHIFT_J            =  74
  SHIFT_K            =  75
  SHIFT_L            =  76
  SHIFT_M            =  77
  SHIFT_N            =  78
  SHIFT_O            =  79
  SHIFT_P            =  80
  SHIFT_Q            =  81
  SHIFT_R            =  82
  SHIFT_S            =  83
  SHIFT_T            =  84
  SHIFT_U            =  85
  SHIFT_V            =  86
  SHIFT_W            =  87
  SHIFT_X            =  88
  SHIFT_Y            =  89
  SHIFT_Z            =  90
  K_L_SQUAREBRACKET  =  91 ' [
  K_Backslash        =  92 ' \
  K_R_SQUAREBRACKET  =  93 ' ]
  K_CARET            =  94 ' ^
  K_UNDERSCORE       =  95 ' _
  K_A                =  97
  K_B                =  98
  K_C                =  99
  K_D                = 100
  K_E                = 101
  K_F                = 102
  K_G                = 103
  K_H                = 104
  K_I                = 105
  K_J                = 106
  K_K                = 107
  K_L                = 108
  K_M                = 109
  K_N                = 110
  K_O                = 111
  K_P                = 112
  K_Q                = 113
  K_R                = 114
  K_S                = 115
  K_T                = 116
  K_U                = 117
  K_V                = 118
  K_W                = 119
  K_X                = 120
  K_Y                = 121
  K_Z                = 122
  K_L_CURLYBRACKET   = 123 ' {
  K_R_CURLYBRACKET   = 125 ' }
  K_TILDE            = 126 ' ~
  ALTGR_C            = 162 ' ¢
  ALTGR_E            = 164 ' (€)
  ALTGR_Y            = 171 ' «
  ALTGR_6            = 172
  ALTGR_2            = 178 ' ²
  ALTGR_3            = 179 ' ³
  ALTGR_M            = 181 ' µ
  ALTGR_R            = 182
  ALTGR_DOT          = 183 ' ·
  ALTGR_1            = 185 ' ¹
  ALTGR_X            = 187 ' »
  SHIFT_AE           = 196 ' Ä
  SHIFT_OE           = 214 ' Ö
  SHIFT_UE           = 220 ' Ü
  K_SS               = 223 ' ß
  K_AE               = 228 ' ä
  ALTGR_A            = 230 ' æ
  ALTGR_D            = 240 ' ð
  K_OE               = 246 ' ö
  ALTGR_O            = 248 ' ø
  K_UE               = 252 ' ü
  ALTGR_P            = 254 ' þ
  K_F1               = 315
  K_F2               = 316
  K_F3               = 317
  K_F4               = 318
  K_F5               = 319
  K_F6               = 320
  K_F7               = 321
  K_F8               = 322
  K_F9               = 323
  K_F10              = 324
  K_HOME             = 327
  K_UP               = 328
  K_PAGEUP           = 329
  K_LEFT             = 331
  K_RIGHT            = 333
  K_END              = 335
  K_DOWN             = 336
  K_PAGEDOWN         = 337
  K_INSERT           = 338
  K_DELETE           = 339
  K_CLOSEWINDOW      = 363
end enum

#if __FB_LANG__ = "fb"
' I like VAR :-)
function GetKeyCode() as KEYCODES
  var code = K_NONE, key = inkey(), chars = len(key)
  if chars then chars-=1 : code = key[chars] or (chars shl 8)
  return code
end function
#else
function GetKeyCode() as KEYCODES
  dim as KEYCODES code  = K_NONE
  dim as string   key   = inkey()
  dim as integer  chars = len(key)
  if chars then 
    code = asc(right(key,1)) : if chars>1 then code += 256
  end if
  return code
end function
#endif
'
' main
'
screenres 640,480
dim as KEYCODES key
while key<>K_ESCAPE andalso key<>K_CLOSEWINDOW
  key =GetKeyCode()
  if key<>K_NONE then locate 1,1 : print "last keycode: " & key & "  "
  sleep 10
wend
Last edited by D.J.Peters on Jul 18, 2016 19:37, edited 12 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

What are the english names for Keycode 35 # and 39 ' ?

Thank you Joshy
mambazo
Posts: 652
Joined: Jul 17, 2005 13:02
Location: Ireland
Contact:

Post by mambazo »

# = hash
' = single quote
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

thanx mambazo, my bad english the others are right?

Joshy
mambazo
Posts: 652
Joined: Jul 17, 2005 13:02
Location: Ireland
Contact:

Post by mambazo »

they all look okay to me :)
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Post by maddogg6 »

'#' could also be called 'Pound Sign' - as described in Voice mail systems in USA. Infers a weight in pounds.

Derived from lables showing weights
Example:

Bag of Ice
Wt# 7.5 (lbs.)

Is pretty common.
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Post by maddogg6 »

Is it legal to have 2

so both are used.

k_hash = 35 ' #
k_poundsign = 35 ' #

?? - I dunno was just curious...
But Id say 'Pound Sign' is more 'english friendly'..

Just my $.02
mambazo
Posts: 652
Joined: Jul 17, 2005 13:02
Location: Ireland
Contact:

Post by mambazo »

erm, in england the term 'pound-sign' usually refers to £

# would be just 'pounds' (lbs)
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Post by coderJeff »

It's think it's only a pound sign in the U.S.
Pound sign could be though to mean '£'.
I'd say hash is good (even though it's not used much in the U.S.)

It is legal to have 2 value names with the same value.
axipher
Posts: 891
Joined: Dec 27, 2005 16:37
Location: Sudbury,Ontario

Post by axipher »

And the common misunderstanding between England English and North America English rises again, they are steadily confused and cause problems, all symbols should have unique international names like the # symbol could be a "horgandog" or a "dizmatapia". The code is pretty good too.
yetifoot
Posts: 1710
Joined: Sep 11, 2005 7:08
Location: England
Contact:

Post by yetifoot »

we used to call # 'gate' but i don't think anyone does anymore

' would be called 'apostrophe'

(england)

heres a wiki article, where they state # is 'number sign'

http://en.wikipedia.org/wiki/Number_sign
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

I have make litle changes for 3 missing key's.
What is the name of keys 94,123,125 please take a look in the source?

Thx Joshy
Last edited by D.J.Peters on Jul 31, 2007 20:03, edited 1 time in total.
Sisophon2001
Posts: 1706
Joined: May 27, 2005 6:34
Location: Cambodia, Thailand, Lao, Ireland etc.
Contact:

Post by Sisophon2001 »

Caret ^
left curly bracket {
right curly bracket }
left square bracket [
right square bracket ]

Garvan
PlayerOne
Posts: 173
Joined: Aug 15, 2005 18:58
Location: UK

Post by PlayerOne »

As I understand it:

Parenthesis: (
Brace: {
Bracket: [

...but I doubt many people would know that, so probably not the best choice for constant names. :) But then, only one set actually has keys of its own, and I note they're called OPENBRACE and CLOSEBRACE in Allegro.bi.
tunginobi
Posts: 655
Joined: Jan 10, 2006 0:44
Contact:

Post by tunginobi »

Backing PlayerOne on the whole brackets deal, except I call brackets "square brackets".
' would be called 'apostrophe'
Try spelling that out as a constant, and you'll start to see why it's not the best identifier for the job. :) I'm happy with "single quote" in the computing context, while using "apostrophe" to sound smart in language-oriented contexts.
Post Reply