Scrupp SVN Manual
Create your own 2D games and applications

Keyboard Support

Functions

scrupp.keyIsDown(key)
Returns the boolean state of the key. key is one of the key strings.
scrupp.setKeyRepeat(delay, interval)
Configures the delay (in ms) after that a permanently pressed key begins to generate repeating key press events which eventually cause repeated calls of the keypressed function (see below). The time between two calls is defined by the interval (in ms). If delay equals 0, key repeating is disabled. After startup, key repeating is disabled as well.

Callbacks

keypressed(key, utf8_string)
Gets called when a key is pressed. Arguments are the key string of the pressed key and its representation as utf-8 encoded string. The utf-8 encoded string takes modifier keys (e. g. SHIFT) into account.
Example: Pressing SHIFT+2 on a US keyboard will result in key == "2" and utf8_string == "@".
keyreleased(key)
Gets calles when a key is released. Argument is the key string of the released key.

Key strings

The first table shows virtual key strings. These keys do not exist. You should not try to use them with the callbacks. Instead of e.g. "SHIFT", test for "LSHIFT" or "RSHIFT"

They should be used with scrupp.keyIsDown() to test for some special keys which happen to be twice on a standard keyboard. scrupp.keyIsDown("SHIFT") will return true if either of the two shift keys is pressed.

"SHIFT"either of the shift keys
"CTRL"either of the ctrl keys
"ALT"either of the alt keys
"META"either of the meta keys
"SUPER"either of the windows keys

The following table shows all key strings usable with Scrupp.

"UNKNOWN"unknown key
"BACKSPACE"backspace
"TAB"tab
"CLEAR"clear
"RETURN"return
"PAUSE"pause
"ESCAPE"escape
"SPACE"space
"!"exclaim
"""quotedbl
"#"hash
"$"dollar
"&"ampersand
"'"quote
"("left parenthesis
")"right parenthesis
"*"asterisk
"+"plus sign
","comma
"-"minus sign
"."period
"/"forward slash
"0"0
"1"1
"2"2
"3"3
"4"4
"5"5
"6"6
"7"7
"8"8
"9"9
":"colon
";"semicolon
"<"less-than sign
"="equals sign
">"greater-than sign
"?"question mark
"@"at
"["left bracket
"\"backslash
"]"right bracket
"^"caret
"_"underscore
"`"grave
"a"a
"b"b
"c"c
"d"d
"e"e
"f"f
"g"g
"h"h
"i"i
"j"j
"k"k
"l"l
"m"m
"n"n
"o"o
"p"p
"q"q
"r"r
"s"s
"t"t
"u"u
"v"v
"w"w
"x"x
"y"y
"z"z
"DELETE"delete
"KP0"keypad 0
"KP1"keypad 1
"KP2"keypad 2
"KP3"keypad 3
"KP4"keypad 4
"KP5"keypad 5
"KP6"keypad 6
"KP7"keypad 7
"KP8"keypad 8
"KP9"keypad 9
"KP_PERIOD"keypad period
"KP_DIVIDE"keypad divide
"KP_MULTIPLY"keypad multiply
"KP_MINUS"keypad minus
"KP_PLUS"keypad plus
"KP_ENTER"keypad enter
"KP_EQUALS"keypad equals
"UP"up arrow
"DOWN"down arrow
"RIGHT"right arrow
"LEFT"left arrow
"INSERT"insert
"HOME"home
"END"end
"PAGEUP"page up
"PAGEDOWN"page down
"F1"F1
"F2"F2
"F3"F3
"F4"F4
"F5"F5
"F6"F6
"F7"F7
"F8"F8
"F9"F9
"F10"F10
"F11"F11
"F12"F12
"F13"F13
"F14"F14
"F15"F15
"NUMLOCK"numlock
"CAPSLOCK"capslock
"SCROLLOCK"scrollock
"RSHIFT"right shift
"LSHIFT"left shift
"RCTRL"right ctrl
"LCTRL"left ctrl
"RALT"right alt
"LALT"left alt
"RMETA"right meta
"LMETA"left meta
"LSUPER"left windows key
"RSUPER"right windows key
"MODE"mode shift
"COMPOSE"compose
"HELP"help
"PRINT"print-screen
"SYSREQ"SysRq
"BREAK"break
"MENU"menu
"POWER"power
"EURO"euro
"UNDO"undo

The source of this table is the SDL man page for SDLKey.

Additionally, there exist strings for keys on international keyboards. They are named from "WORLD_0" to "WORLD_95".

Example

scrupp.init("Keyboard Test", 600, 400, 32, false)

require "font"

local font = Font("fonts/Vera.ttf", 20)

local text = "Press any key."

main = {
	render = function(dt)
		font:print(10, 10, text)
	end,
	
	keypressed = function(key)
		text = key .. " pressed."
		
		-- the escape key exits the demo
		if key == "ESCAPE" then
			scrupp.exit()
		end
	end,
	
	keyreleased = function(key)
		text = key .. " released."
	end
}	

Hosted by
SourceForge.net Logo

Valid XHTML 1.0!

Last modified Thu Feb 23, 2012