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

Blitz3DBlitzPlusBlitzBasic

KeyHit

KeyHit:Int32 key:Int32
Parameter Mode Type Default Description
key In Int32 required The scancode of the key, 1 to 237 (the DirectInput scancodes of the original, see Scan Codes). Any other value is 0.

Returns: How many times the key was pressed since the last call.

Description

Counts how often a key was pressed since the last time KeyHit asked about that same key. The count starts again from zero on every call, so the key must be released and pressed again to count another time. This is the right choice for one-shot actions like pausing or shooting, while KeyDown suits continuous movement.

Differences

  • Keys that DirectInput has no code for, such as F16 to F24 and Help, are only reachable with VKeyHit.
  • The Device argument is a BlitzLLVM extension: the original has no such argument and only knows one keyboard.

Examples

Graphics 320, 240, 0, 2
SetBuffer BackBuffer()
Local hits = 0
While Not KeyHit(1)
	If KeyHit(57) Then hits = hits + 1
	Cls
	Text 10, 10, "Press Space, Escape ends"
	Text 10, 30, "Space was pressed " + hits + " times"
	Flip
Wend

Related Commands

GetKey, KeyDown, KeyWait, VKeyDown, VKeyHit, WaitKey

Home · Command Index



Differences
Language Features
BlitzBasic
Blitz3D
BlitzPlus

Clone this wiki locally