Microsoft Small Basic

Program Listing: GRM149
' Key Input Test
' Copyright © 2015 Nonki Takahashi. The MIT License.
'
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)
GraphicsWindow.Title = "Key Test"
GraphicsWindow.BrushColor = "Black"
shpTxt = Shapes.AddText("")
tbox = Controls.AddTextBox(200, 10)
btn = Controls.AddButton("Clear", 560, 10)
Controls.ButtonClicked = OnButtonClicked
Shapes.Move(shpTxt, 10, 10)
buf = ""
Controls.TextTyped = OnTextTyped
GraphicsWindow.TextInput = OnTextInput
GraphicsWindow.KeyUp = OnKeyUp
GraphicsWindow.KeyDown = OnKeyDown
Sub OnButtonClicked
buf = ""
Shapes.SetText(shpTxt, buf)
EndSub
Sub OnTextTyped
txt = Controls.GetTextBoxText(tbox)
buf = buf + "TextTyped:" + txt + CRLF
Shapes.SetText(shpTxt, buf)
EndSub
Sub OnTextInput
txt = GraphicsWindow.LastText
buf = buf + "TextInput:" + txt + " (" + Text.GetCharacterCode(txt) + ")" + CRLF
Shapes.SetText(shpTxt, buf)
EndSub
Sub OnKeyUp
key = GraphicsWindow.LastKey
buf = buf + "KeyUp:" + key + CRLF
Shapes.SetText(shpTxt, buf)
EndSub
Sub OnKeyDown
key = GraphicsWindow.LastKey
buf = buf + "KeyDonw:" + key + CRLF
Shapes.SetText(shpTxt, buf)
EndSub