Difference between revisions of "KeyCode"

From GiderosMobile
(removed language stuff)
(added example)
Line 8: Line 8:
 
KeyCode table holds the key code constants. These map directly to a physical key on the keyboard.
 
KeyCode table holds the key code constants. These map directly to a physical key on the keyboard.
  
=== Example ===
+
=== Examples ===
 
'''Listening for back button'''
 
'''Listening for back button'''
 
<source lang="lua">
 
<source lang="lua">
Line 16: Line 16:
 
     end
 
     end
 
end)
 
end)
 +
</source>
 +
 +
'''Full screen'''
 +
<source lang="lua">
 +
isfullscreen = false
 +
 +
function setFullScreen(xbool)
 +
application:setFullScreen(xbool)
 +
end
 +
 +
function myKeysPressed()
 +
self:addEventListener(Event.KEY_DOWN, function(e)
 +
-- modifier
 +
local modifier = application:getKeyboardModifiers()
 +
local alt = (modifier & KeyCode.MODIFIER_ALT) > 0
 +
-- switch full screen
 +
if alt and e.keyCode == KeyCode.ENTER then
 +
isfullscreen = not isfullscreen
 +
setFullScreen(isfullscreen)
 +
end
 +
end)
 +
end
 
</source>
 
</source>
  

Revision as of 19:29, 11 December 2021

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
Available since: Gideros 2011.6
Inherits from: Object

Description

KeyCode table holds the key code constants. These map directly to a physical key on the keyboard.

Examples

Listening for back button

stage:addEventListener(Event.KEY_DOWN, function(event)
    if event.keyCode == KeyCode.BACK then
        application:exit()
    end
end)

Full screen

isfullscreen = false

function setFullScreen(xbool)
	application:setFullScreen(xbool)
end

function myKeysPressed()
	self:addEventListener(Event.KEY_DOWN, function(e)
		-- modifier
		local modifier = application:getKeyboardModifiers()
		local alt = (modifier & KeyCode.MODIFIER_ALT) > 0
		-- switch full screen
		if alt and e.keyCode == KeyCode.ENTER then
			isfullscreen = not isfullscreen
			setFullScreen(isfullscreen)
		end
	end)
end

Methods

Events

Constants

KeyCode.A
KeyCode.ALT
KeyCode.B
KeyCode.BACK
KeyCode.BACKSPACE
KeyCode.C
KeyCode.CENTER
KeyCode.CTRL
KeyCode.D
KeyCode.DELETE
KeyCode.DOWN
KeyCode.E
KeyCode.END
KeyCode.ENTER
KeyCode.ESC
KeyCode.F
KeyCode.G
KeyCode.H
KeyCode.HOME
KeyCode.I
KeyCode.INSERT
KeyCode.J
KeyCode.K
KeyCode.L
KeyCode.L1
KeyCode.LEFT
KeyCode.M
KeyCode.MENU
KeyCode.MODIFIER_ALT
KeyCode.MODIFIER_CTRL
KeyCode.MODIFIER_META
KeyCode.MODIFIER_NONE
KeyCode.MODIFIER_SHIFT
KeyCode.MOUSE_LEFT
KeyCode.MOUSE_MIDDLE
KeyCode.MOUSE_NONE
KeyCode.MOUSE_RIGHT
KeyCode.N
KeyCode.NUM_0
KeyCode.NUM_1
KeyCode.NUM_2
KeyCode.NUM_3
KeyCode.NUM_4
KeyCode.NUM_5
KeyCode.NUM_6
KeyCode.NUM_7
KeyCode.NUM_8
KeyCode.NUM_9
KeyCode.O
KeyCode.P
KeyCode.PAGEDOWN
KeyCode.PAGEUP
KeyCode.Q
KeyCode.R
KeyCode.R1
KeyCode.RIGHT
KeyCode.S
KeyCode.SEARCH
KeyCode.SELECT
KeyCode.SHIFT
KeyCode.SPACE
KeyCode.START
KeyCode.T
KeyCode.TAB
KeyCode.U
KeyCode.UP
KeyCode.V
KeyCode.W
KeyCode.X
KeyCode.Y
KeyCode.Z
KeyCode.F1
KeyCode.F2
KeyCode.F3
KeyCode.F4
KeyCode.F5
KeyCode.F6
KeyCode.F7
KeyCode.F8
KeyCode.F9
KeyCode.F10
KeyCode.F11
KeyCode.F12