Microsoft Small Basic

Program Listing: CND797
'password : challenge oktober 2015
' 151015 WhTurner ### for my keyboard, need possible adjustment for others [ oemspec ...]

GraphicsWindow.Height=200
GraphicsWindow.DrawRectangle(50,30,250,30)
GraphicsWindow.DrawText(50,10,"give password")
cw="|"
GraphicsWindow.FontSize=18
GraphicsWindow.DrawText(50,35," "+cw)

'############### definitions for translation special keys ##################
special=")!@#$%^&*(_" 'shifted numberkeys
dummy="1=home;2=pageup;3=up;4=left;5=clear;6=right;7=end;8=pagedown;9=down;10=next;11=insert;12=delete;13=space" 'ignore
numspec="1=divide;2=multiply;3=subtract;4=add;5=return;6=decimal" 'special keys numericalblock
numkey="1=/;2=*;3=-;4=+;6=."
oemspec="1=3;2=minus;3=plus;4=5;5=comma;6=period;7=question;8=quotes;9=1;10=openbrackets;11=6" 'specialkeys starting with "oem"
oemkey="1=`;2=-;3=\=;4=\\;5=,;6=.;7=/;8=';9=\;;10=[;11=]"
oemkeyshift="1=~;2=_;3=+;4=|;5=<;6=>;7=?;9=:;10={;11=}"
oemkeyshift[8]=Text.GetCharacter(34)
' # # # # # # # # # # # # # # # # # # # # # # # ^^^^

GraphicsWindow.KeyDown=KD
GraphicsWindow.KeyUp=KU

Sub KU
key=GraphicsWindow.LastKey
key=Text.ConvertToLowerCase(key)
If key="leftshift" or key="rightshift" Then
shifted="False"
ElseIf key="back" then
key=""
pw=Text.GetSubText(pw,1,Text.GetLength(pw)-1)
cw=Text.GetSubTextToEnd(cw,2)
Else ' not shift or back
For i=1 To array.GetItemCount(dummy) 'shifted numpad (and space) : disregard
If key=dummy[i] then
key=""
i=99
EndIf
endfor
For i=1 To Array.GetItemCount(numspec) 'specialkeys numpad : translate
If key=numspec[i] Then
key=numkey[i]
i=99
EndIf
EndFor

If shifted="True" Then
If Text.StartsWith(key,"oem") then
For i=1 To Array.GetItemCount(oemspec)
If key="oem"+oemspec[i] then
key=oemkeyshift[i]
i=99
EndIf
EndFor
EndIf 'oem
If Text.GetLength(key)=2 And Text.StartsWith(key,"d") Then ' numberkeys on top
key=Text.GetSubTextToEnd(key,2)
key=Text.GetSubText(special,key+1,1)
EndIf
key=Text.ConvertToUpperCase(key)

Else ' not shifted
If Text.StartsWith(key,"oem") then
For i=1 To Array.GetItemCount(oemspec)
If key="oem"+oemspec[i] then
key=oemkey[i]
i=99
EndIf
EndFor
EndIf
If Text.GetLength(key)=2 And Text.StartsWith(key,"d") Then 'numberkeys on top
key=Text.GetSubTextToEnd(key,2)
ElseIf Text.StartsWith(key,"numpad") then 'numerical block of keys
key=Text.GetSubTextToEnd(key,7)
EndIf
EndIf 'shifted
If key<>"" then
pw=Text.Append(pw,key)
cw="*"+cw
endif
EndIf 'key = ....
GraphicsWindow.BrushColor="white"
GraphicsWindow.FillRectangle(50,31,248,28)
GraphicsWindow.FillRectangle(50,151,248,28)
GraphicsWindow.BrushColor="Blue"
GraphicsWindow.DrawText(50,35," "+cw)
GraphicsWindow.BrushColor="Orange"
GraphicsWindow.DrawText(50,150,pw)
key=""
EndSub

Sub KD
keyd=GraphicsWindow.LastKey
If keyd="LeftShift" or keyd= "RightShift" Then
shifted="True"
keyd=""
endif
EndSub