Skip to content
Narta Xaymar Dirks edited this page Nov 25, 2026 · 10 revisions

KeyHit BlitzBasic

KeyHit:Int32 key:Int32, device:Int32=-1
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.
device In Int32 -1 Only look at this keyboard, counted from 0 as in KeyboardDeviceCount. -1 (the default) means all keyboards together.

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 BlitzBasic, KeyDown BlitzBasic, KeyWait BlitzPlus, VKeyDown BlitzLLVM, VKeyHit BlitzLLVM, WaitKey BlitzBasic

Home · Command Index


Getting started

Language

Tools


Language Features
BlitzBasic
Blitz3D
BlitzPlus
Differences

More

Clone this wiki locally