Share via


Small Basic: Key Input

This article is about accepting keyboard input in Microsoft Small Basic.


GraphicsWindow

In the graphics window, there are three methods to accept input.

  • Text box controls
  • Text input event
  • Key up and down events

Text Box Controls

Each Controls.AddTextBox() and Controls.AddMultiLineTextBox() adds a text input box to the graphics window.  In a text input box, you can input from keyboard and by Controls.GetTextBoxText(), can obtain the input value.  You can set event handler with Controls.TextTyped event.

TextInput Event

The TextInput event is fired when a key is typed and you can subscribe to that with a handler.  You can also obtain text using the GraphicsWindow.LastText property.

KeyDown and KeyUp Events

You can set key down (up) event handlers by subscribing to  GraphicsWindow.KeyDown and GraphicsWindow.KeyUp events.
Sample code follows:

GraphicsWindow.DrawText(10, 10,  "Hit any key to dump.")
GraphicsWindow.KeyDown = OnKeyDown
Sub OnKeyDown
  TextWindow.WriteLine(GraphicsWindow.LastKey)
EndSub

Following table shows values of GraphicsWindow.LastKey .

Key top E Key top J LastKey Comments
A-Z A-Z A-Z  
/ \ AbntC1 Brazil key, IME=ENG
+ + Add numeric keypad
Apps  
Back Space Back  
Break Break Cancel Ctrl+Pause
Caps Lock Caps Lock Capital  
5 5 Clear !NumLock
. . Decimal NumLock
Delete Delete Delete  
/ / Divide numeric keypad
Down  
End End End  
Esc Esc Escape  
F1-F9 F1-F9 F1-F9  
F11-F12 F11-F12 F11-F12  
0-9 0-9 D0-D9  
Home Home Home  
N/A 無変換 ImeNonConvert non convert
Insert Insert Insert  
Left  
Ctrl Ctrl LeftCtrl left control
⇧Shift LeftShift  
N/A LWin display
LWin left Window
* * Multiply numeric keypad
Page Down PgDn Next
Num Lock Num Lk NumLock  
0-9 0-9 NumPad0-NumPad9 NumLock
; + Oem1 IME=ENG
' : Oem1 IME=J
` 半角/全角 Oem3 IME=ENG
[ @ Oem3 IME=J
\ ] Oem5 IME=ENG
N/A ¥ Oem5 IME=J
] [ Oem6 IME=ENG
\ ] Oem6 IME=J
/ \ OemBackslash IME=J
, , OemComma  
- - OemMinus
[ @ OemOpenBrackets IME=ENG
] [ OemOpenBrackets IME=J
. . OemPeriod  
= ^ OemPlus IME=ENG
; + OemPlus IME=J
/ / OemQuestion  
' : OemQuotes IME=ENG
= ^ OemQuotes IME=J
Page Up PgUp PageUp  
Pause Pause Pause  
Enter Enter Return  
Right  
Ctrl Ctrl RightCtrl right control
⇧Shift RightShift  
RWin right Windows
- - Subtract numeric keypad
Scroll Lock Scr Lk Scroll scroll lock
(Space) (Space) Space  
Alt Alt System  
F10 F10 System  
Tab Tab Tab  
Up  
VolumeDown
VolumeMute
VolumeUp
Print Scrn Prt Sc N/A print screen
N/A ¥ N/A IME=ENG
` 半角/全角 N/A IME=J
N/A ひらがな N/A hiragana
N/A 変換 N/A convert

Input Focus

Input focus is the location (control) where the user is currently directing input.  Input focus can be changed with [Tab] key or mouse click and is displayed as light blue. You can check which control has the input focus with following sample program.  
Note that if the input focus is on a text input box, the TextInput event will not fire.  If the input focus is not on any text input box, TextInput event fires.

Sample Program

  • Key Input Test (GRM149) - shows events GraphicsWindow.KeyUp, GraphicsWindow.KeyDown, GraphicsWindow.TextInput, and Controls.TextTyped.

Known Issues

When the published program is run in a browser (in remote), following issues will be occurred.

  • Input focuses for GraphicsWindow.KeyDown and GraphicsWindow.KeyUp event handlers can be lost when there is a text box control in local but the input focus can be rounded among controls including key event handlers by pushing tab key in remote.
  • GraphicsWindow.LastKey becomes "LeftShift" or "RightShift" for [Shift] key in local but "Shift" in remote.
  • GraphicsWindow.LastText returns as same key name as GraphicsWindow.LastKey in remote.

TextWindow

For the text window, TextWindow.Read() and TextWindow.ReadNum() are used to input from keyboard.

Read and ReadNum Operations

TextWindow.Read() inputs text and TextWindow.ReadNum() inputs number from keyboard.

ReadKey Operation is Obsolete

TextWindow.ReadKey() operation is old operation.  But it can work because of backward compatibility.

See Also

Other Resources

Other Languages