Scrupp 0.1 Manual
Create your own 2D games and applications

Functions

key.isDown(key)
Returns the boolean state of the key. key is one of the key constants.

Callbacks

keypressed(key)
Gets called when a key is pressed. Argument is the key constant of the pressed key.
keyreleased(key)
Gets calles when a key is released. Argument is the key constants of the released key.

Key constants

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

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

key.SHIFTeither of the shift keys
key.CTRLeither of the ctrl keys
key.ALTeither of the alt keys
key.METAeither of the meta keys
key.SUPEReither of the windows keys

The following table shows all key constants usable with Scrupp.

key.BACKSPACE'\b'backspace
key.TAB'\t'tab
key.CLEARclear
key.RETURN'\r'return
key.PAUSEpause
key.ESCAPE'^['escape
key.SPACE' 'space
key.EXCLAIM'!'exclaim
key.QUOTEDBL'"'quotedbl
key.HASH'#'hash
key.DOLLAR'$'dollar
key.AMPERSAND'&'ampersand
key.QUOTE'''quote
key.LEFTPAREN'('left parenthesis
key.RIGHTPAREN')'right parenthesis
key.ASTERISK'*'asterisk
key.PLUS'+'plus sign
key.COMMA','comma
key.MINUS'-'minus sign
key.PERIOD'.'period
key.SLASH'/'forward slash
key.0'0'0
key.1'1'1
key.2'2'2
key.3'3'3
key.4'4'4
key.5'5'5
key.6'6'6
key.7'7'7
key.8'8'8
key.9'9'9
key.COLON':'colon
key.SEMICOLON';'semicolon
key.LESS'<'less-than sign
key.EQUALS'='equals sign
key.GREATER'>'greater-than sign
key.QUESTION'?'question mark
key.AT'@'at
key.LEFTBRACKET'['left bracket
key.BACKSLASH'\'backslash
key.RIGHTBRACKET']'right bracket
key.CARET'^'caret
key.UNDERSCORE'_'underscore
key.BACKQUOTE'`'grave
key.a'a'a
key.b'b'b
key.c'c'c
key.d'd'd
key.e'e'e
key.f'f'f
key.g'g'g
key.h'h'h
key.i'i'i
key.j'j'j
key.k'k'k
key.l'l'l
key.m'm'm
key.n'n'n
key.o'o'o
key.p'p'p
key.q'q'q
key.r'r'r
key.s's's
key.t't't
key.u'u'u
key.v'v'v
key.w'w'w
key.x'x'x
key.y'y'y
key.z'z'z
key.DELETE'^?'delete
key.KP0keypad 0
key.KP1keypad 1
key.KP2keypad 2
key.KP3keypad 3
key.KP4keypad 4
key.KP5keypad 5
key.KP6keypad 6
key.KP7keypad 7
key.KP8keypad 8
key.KP9keypad 9
key.KP_PERIOD'.'keypad period
key.KP_DIVIDE'/'keypad divide
key.KP_MULTIPLY'*'keypad multiply
key.KP_MINUS'-'keypad minus
key.KP_PLUS'+'keypad plus
key.KP_ENTER'\r'keypad enter
key.KP_EQUALS'='keypad equals
key.UPup arrow
key.DOWNdown arrow
key.RIGHTright arrow
key.LEFTleft arrow
key.INSERTinsert
key.HOMEhome
key.ENDend
key.PAGEUPpage up
key.PAGEDOWNpage down
key.F1F1
key.F2F2
key.F3F3
key.F4F4
key.F5F5
key.F6F6
key.F7F7
key.F8F8
key.F9F9
key.F10F10
key.F11F11
key.F12F12
key.F13F13
key.F14F14
key.F15F15
key.NUMLOCKnumlock
key.CAPSLOCKcapslock
key.SCROLLOCKscrollock
key.RSHIFTright shift
key.LSHIFTleft shift
key.RCTRLright ctrl
key.LCTRLleft ctrl
key.RALTright alt
key.LALTleft alt
key.RMETAright meta
key.LMETAleft meta
key.LSUPERleft windows key
key.RSUPERright windows key
key.MODEmode shift
key.HELPhelp
key.PRINTprint-screen
key.SYSREQSysRq
key.BREAKbreak
key.MENUmenu
key.POWERpower
key.EUROeuro

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

Example

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

main = {
	render = function(dt)
		-- we need at least an empty render function
	end,
	
	keypressed = function(k)
		-- check if a valid letter key is pressed;
		-- string.byte is a Lua function that returns 
		-- the ASCII value of a char
		if k>=string.byte('a') and k<=string.byte('z') then
			-- if a letter key is pressed, then the argument k 
			-- is a number (the ASCII code);
			-- string.char is a Lua function that returns
			-- the char of such a code
			local ch = string.char(k)
			-- check whether any of the two shift keys is pressed
			if key.isDown(key.SHIFT) then
				-- make the letter uppercase
				ch = string.upper(ch)
			end				
			-- print the letter of the key;
			-- string.char is a Lua function that returns
			-- the char of a ASCII value
			print(ch .. " pressed")
		end
		
		-- the escape key exits the demo
		if k == key.ESCAPE then
			game.exit()
		end
	end,
	
	keyreleased = function(k)
		print("key released")
	end
}	

Hosted by
SourceForge.net Logo

Valid XHTML 1.0!

Last modified Mon May 26, 2008