Microsoft Small Basic
Program Listing: SBR991
'************************************************************'
' Multiple Keys Test (v2.02)
' by galgtonold (2013/Oct)
' mod GoToLoop
' http://social.msdn.microsoft.com/Forums/en-US/
'fea3b8a2-ee28-45dc-a06b-0dd0c4754e24/
'reacting-on-multiple-arrow-keys-simultanously
'************************************************************'
'---------------------------------------------------------------------------'
GW = 150
GH = 150
isUp = "False"
isDown = "False"
isLeft = "False"
isRight = "False"
isWaitingKey = "True"
'---------------------------------------------------------------------------'
GraphicsWindow.Title = "Mult Keys"
GraphicsWindow.CanResize = "False"
GraphicsWindow.BackgroundColor = "MidnightBlue"
GraphicsWindow.Width = GW
GraphicsWindow.Height = GH
CreateLabels()
GraphicsWindow.KeyDown = KeyPressed
GraphicsWindow.KeyUp = KeyReleased
'---------------------------------------------------------------------------'
Loop:
While isWaitingKey
Program.Delay(10)
EndWhile
isWaitingKey = "True"
UpdateLabels()
Goto Loop
'---------------------------------------------------------------------------'
Sub KeyPressed
k = GraphicsWindow.LastKey
If k = "Up" Then
isUp = "True"
ElseIf k = "Down" Then
isDown = "True"
ElseIf k = "Left" Then
isLeft = "True"
ElseIf k = "Right" Then
isRight = "True"
ElseIf k = "Escape" Then
Sound.PlayChimeAndWait()
Program.End()
EndIf
isWaitingKey = "False"
EndSub
'---------------------------------------------------------------------------'
Sub KeyReleased
kk = GraphicsWindow.LastKey
If kk = "Up" Then
isUp = "False"
ElseIf kk = "Down" Then
isDown = "False"
ElseIf kk = "Left" Then
isLeft = "False"
ElseIf kk = "Right" Then
isRight = "False"
EndIf
isWaitingKey = "False"
EndSub
'---------------------------------------------------------------------------'
Sub CreateLabels
GraphicsWindow.BrushColor = "Gold"
up = Shapes.AddText("Up: False")
down = Shapes.AddText("Down: False")
left = Shapes.AddText("Left: False")
right = Shapes.AddText("Right: False")
Shapes.Move(up 40, 25)
Shapes.Move(down 40, 50)
Shapes.Move(left 40, 75)
Shapes.Move(right 40, 100)
EndSub
'---------------------------------------------------------------------------'
Sub UpdateLabels
Shapes.SetText(up, "Up: " + isUp)
Shapes.SetText(down, "Down: " + isDown)
Shapes.SetText(left, "Left: " + isLeft)
Shapes.SetText(right, "Right: " + isRight)
EndSub
'---------------------------------------------------------------------------'