Skip to content
Narta Xaymar Dirks edited this page Nov 1, 2026 · 5 revisions

Blitz3DBlitzPlusBlitzBasic

GetKey

GetKey:Int32

Returns: The character code of the next typed character, or 0 if there is none.

Description

Takes the next typed character out of the keyboard queue and returns its character code, or 0 when nothing was typed since the last call. It follows what the keyboard layout produces, so Shift+A gives 65 and plain A gives 97. A few keys that do not type a character still give a code: Enter 13, Backspace 8, Tab 9 and Escape 27, and the editing keys give the codes of the original: Home 1, End 2, Insert 3, Delete 4, Page Up 5, Page Down 6, and the arrows Up 28, Down 29, Left 30 and Right 31. Keys without any character, such as Shift and the function keys, are not reported here, so use KeyDown or KeyHit for those.

The character code is not the scancode that KeyDown and KeyHit use.

Differences

  • The queue holds 64 characters, and the oldest ones are dropped when it is full.
  • Only characters that fit into one byte (code 1 to 255) are delivered. Characters outside the Latin-1 range, such as many symbols typed through an IME, are skipped.

Examples

Graphics 320, 240, 0, 2
SetBuffer BackBuffer()
Local typed$ = ""
While Not KeyHit(1)
	Local c = GetKey()
	If c = 8 And Len(typed) > 0 Then typed = Left(typed, Len(typed) - 1)
	If c >= 32 And c < 127 Then typed = typed + Chr(c)
	Cls
	Text 10, 10, "Type something, Escape ends:"
	Text 10, 30, typed + "_"
	Flip
Wend

Related Commands

KeyDown, KeyHit, KeyWait, VKeyDown, VKeyHit, WaitKey

Home · Command Index



Differences
Language Features
BlitzBasic
Blitz3D
BlitzPlus

Clone this wiki locally