these two functions will convert a scancode to the actual key name (as a string ) and vice versa.
function sccode(letter$)
`make all inputted string lowercase to make things easier to recognise
letter$ = lower$(letter$)
`allow for some know abreviations/variations of key names
if letter$ = "esc" then letter$ = "esc"
if letter$ = "lshift" then letter$ = "left shift"
if letter$ = "rshift" then letter$ = "right shift"
`here's the juice,we give out the scancode of the key named
if letter$="q" then value=16
if letter$="w" then value=17
if letter$="e" then value=18
if letter$="r" then value=19
if letter$="t" then value=20
if letter$="y" then value=21
if letter$="u" then value=22
if letter$="i" then value=23
if letter$="o" then value=24
if letter$="p" then value=25
if letter$="a" then value=30
if letter$="s" then value=31
if letter$="d" then value=32
if letter$="f" then value=33
if letter$="g" then value=34
if letter$="h" then value=35
if letter$="j" then value=36
if letter$="k" then value=37
if letter$="l" then value=38
if letter$="z" then value=44
if letter$="x" then value=45
if letter$="c" then value=46
if letter$="v" then value=47
if letter$="b" then value=48
if letter$="n" then value=49
if letter$="m" then value=50
if letter$="1" then value=2
if letter$="2" then value=3
if letter$="3" then value=4
if letter$="4" then value=5
if letter$="5" then value=6
if letter$="6" then value=7
if letter$="7" then value=8
if letter$="8" then value=9
if letter$="9" then value=10
if letter$="0" then value=11
if letter$="esc" then value=1
if letter$="-" then value=12
if letter$="=" then value=13
if letter$="backspace" then value=14
if letter$="tab" then value=15
if letter$="[" then value=26
if letter$="]" then value=27
if letter$="enter" then value=28
if letter$="ctrl" then value=29
if letter$=";" then value=39
if letter$="'" then value=40
if letter$="`" then value=41
if letter$="left shift" then value=42
if letter$="\" then value=43
if letter$="," then value=51
if letter$="." then value=52
if letter$="/" then value=53
if letter$="right shift" then value=54
if letter$="print screen" then value=55
if letter$="alt" then value=56
if letter$="space" then value=57
if letter$="caps" then value=58
if letter$="f1" then value=59
if letter$="f2" then value=60
if letter$="f3" then value=61
if letter$="f4" then value=62
if letter$="f5" then value=63
if letter$="f6" then value=64
if letter$="f7" then value=65
if letter$="f8" then value=66
if letter$="f9" then value=67
if letter$="f10" then value=68
if letter$="num lock" then value=69
if letter$="scroll" then value=70
if letter$="home" then value=71
if letter$="up" then value=72
if letter$="page up" then value=73
if letter$="-" then value=74
if letter$="left" then value=75
if letter$="centre" then value=76
if letter$="right" then value=77
if letter$="+" then value=78
if letter$="end" then value=79
if letter$="down" then value=80
if letter$="page down" then value=81
if letter$="insert" then value=82
if letter$="delete" then value=83
if letter$="f11" then value=87
if letter$="f12" then value=88
if letter$="macro" then value=111
endfunction value
function alphabet(value)
if value=16 then letter$="q"
if value=17 then letter$="w"
if value=18 then letter$="e"
if value=19 then letter$="r"
if value=20 then letter$="t"
if value=21 then letter$="y"
if value=22 then letter$="u"
if value=23 then letter$="i"
if value=24 then letter$="o"
if value=25 then letter$="p"
if value=30 then letter$="a"
if value=31 then letter$="s"
if value=32 then letter$="d"
if value=33 then letter$="f"
if value=34 then letter$="g"
if value=35 then letter$="h"
if value=36 then letter$="j"
if value=37 then letter$="k"
if value=38 then letter$="l"
if value=44 then letter$="z"
if value=45 then letter$="x"
if value=46 then letter$="c"
if value=47 then letter$="v"
if value=48 then letter$="b"
if value=49 then letter$="n"
if value=50 then letter$="m"
if value=2 then letter$="1"
if value=3 then letter$="2"
if value=4 then letter$="3"
if value=5 then letter$="4"
if value=6 then letter$="5"
if value=7 then letter$="6"
if value=8 then letter$="7"
if value=9 then letter$="8"
if value=10 then letter$="9"
if value=11 then letter$="0"
if value=1 then letter$="ESC"
if value=12 then letter$="-"
if value=13 then letter$="="
if value=14 then letter$="Backspace"
if value=15 then letter$="Tab"
if value=26 then letter$="["
if value=27 then letter$="]"
if value=28 then letter$="Enter"
if value=29 then letter$="Ctrl"
if value=39 then letter$=";"
if value=40 then letter$="'"
if value=41 then letter$="`"
if value=42 then letter$="Left Shift"
if value=43 then letter$="\"
if value=51 then letter$=","
if value=52 then letter$="."
if value=53 then letter$="/"
if value=54 then letter$="Right Shift"
if value=55 then letter$="Print Screen"
if value=56 then letter$="Alt"
if value=57 then letter$="Space"
if value=58 then letter$="Caps"
if value=59 then letter$="F1"
if value=60 then letter$="F2"
if value=61 then letter$="F3"
if value=62 then letter$="F4"
if value=63 then letter$="F5"
if value=64 then letter$="F6"
if value=65 then letter$="F7"
if value=66 then letter$="F8"
if value=67 then letter$="F9"
if value=68 then letter$="F10"
if value=69 then letter$="Num Lock"
if value=70 then letter$="Scroll"
if value=71 then letter$="Home"
if value=72 then letter$="Up"
if value=73 then letter$="Page Up"
if value=74 then letter$="-"
if value=75 then letter$="Left"
if value=76 then letter$="Centre"
if value=77 then letter$="Right"
if value=78 then letter$="+"
if value=79 then letter$="End"
if value=80 then letter$="Down"
if value=81 then letter$="Page Down"
if value=82 then letter$="Insert"
if value=83 then letter$="Delete"
if value=87 then letter$="F11"
if value=88 then letter$="F12"
if value=111 then letter$="Macro"
endfunction letter$
Mouseclick() detects when the mouse is pressed in.I made two functions which tell you when the mouse or any key was pressed out, ie. released.Some may find this useful since mouseout() or keyout() can't happen continually like mouseclick() for example you have a menu and when you click a button and it goes to the next screen and there is a new button at the same location,if you use mouseclick() it will detect it and will act as if you pressed the second button too.There are a few other uses.
SYNC ON:SYNC RATE 60
`we must initialise the function
`ie load arrays needed
mouseout(0)
keyout(0,0)
set cursor 0,100
DO
text 10,10,"try pressing and then letting go of 'W',then try the mouse!"
mout = mouseout(1)
kout = keyout(1,17)
if mout > 0 then print "MOUSEOUT "+str$(mout)
if kout > 0 then print "W RELEASED"
`unload function arrays
if escapekey() = 1 then mouseout(2):keyout(2,0)
SYNC
LOOP
function keyout(key,scode)
if key = 0
`assuming there can't be more than 100 scancodes
dim scode(100)
endif
if key = 1
if scode(scode)>0
if keystate(scode) = 0
result = scode(scode)
else
result = 0
endif
endif
scode(scode) = keystate(scode)
endif
if key = 2
undim scode(0)
endif
endfunction result
function mouseout(ins)
if ins=0
dim mouse_click(0)
endif
if ins=1
if mouse_click(0)>0
if mouseclick()=0
mresult=mouse_click(0)
else
mresult=0
endif
endif
mouse_click(0)=mouseclick()
endif
if ins=2
undim mouse_click(0)
endif
endfunction mresult
"hello my brother. hello and goodbye."
-black man on drugs outside a big white house