Difference between revisions of "KeyCode"

From GiderosMobile
(Created page with "__NOTOC__ '''Supported platforms:''' <br/> '''Available since:''' Gideros 2011.6<br/> === Description === <br /> KeyCode table holds the key code constants. These map directly...")
 
 
(23 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
'''Supported platforms:''' <br/>
+
<!-- GIDEROSOBJ:KeyCode -->
 +
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
 
'''Available since:''' Gideros 2011.6<br/>
 
'''Available since:''' Gideros 2011.6<br/>
 +
'''Inherits from:''' [[Object]]<br/>
 +
 
=== Description ===
 
=== Description ===
<br />
+
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.<br />
+
 
 +
=== Examples ===
 +
'''Listening for back button on phones/tablets'''
 +
<syntaxhighlight lang="lua">
 +
stage:addEventListener(Event.KEY_DOWN, function(event)
 +
    if event.keyCode == KeyCode.BACK then
 +
        application:exit()
 +
    end
 +
end)
 +
</syntaxhighlight>
 +
 
 +
'''Full screen'''
 +
<syntaxhighlight 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
 +
</syntaxhighlight>
 +
 
 
{|-
 
{|-
| style="width: 50%;"|
+
| style="width: 50%; vertical-align:top;"|
 +
 
 
=== Methods ===
 
=== Methods ===
| style="width: 50%;"|
+
 
 +
| style="width: 50%; vertical-align:top;"|
 
=== Events ===
 
=== Events ===
 
=== Constants ===
 
=== Constants ===
 +
'''[[KeyCode Constants]]'''
 +
<!--GIDEROSCST:KeyCode.A 65-->
 +
<!--GIDEROSCST:KeyCode.ALT 18-->
 +
<!--GIDEROSCST:KeyCode.B 66-->
 +
<!--GIDEROSCST:KeyCode.BACK 301-->
 +
<!--GIDEROSCST:KeyCode.BACKSPACE 8-->
 +
<!--GIDEROSCST:KeyCode.C 67-->
 +
<!--GIDEROSCST:KeyCode.CENTER 304-->
 +
<!--GIDEROSCST:KeyCode.CTRL 17-->
 +
<!--GIDEROSCST:KeyCode.D 68-->
 +
<!--GIDEROSCST:KeyCode.DELETE 403-->
 +
<!--GIDEROSCST:KeyCode.DOWN 40-->
 +
<!--GIDEROSCST:KeyCode.E 69-->
 +
<!--GIDEROSCST:KeyCode.END 401-->
 +
<!--GIDEROSCST:KeyCode.ENTER 13-->
 +
<!--GIDEROSCST:KeyCode.ESC 27-->
 +
<!--GIDEROSCST:KeyCode.F 70-->
 +
<!--GIDEROSCST:KeyCode.G 71-->
 +
<!--GIDEROSCST:KeyCode.H 72-->
 +
<!--GIDEROSCST:KeyCode.HOME 400-->
 +
<!--GIDEROSCST:KeyCode.I 73-->
 +
<!--GIDEROSCST:KeyCode.INSERT 402-->
 +
<!--GIDEROSCST:KeyCode.J 74-->
 +
<!--GIDEROSCST:KeyCode.K 75-->
 +
<!--GIDEROSCST:KeyCode.L 76-->
 +
<!--GIDEROSCST:KeyCode.L1 307-->
 +
<!--GIDEROSCST:KeyCode.LEFT 37-->
 +
<!--GIDEROSCST:KeyCode.M 77-->
 +
<!--GIDEROSCST:KeyCode.MENU 303-->
 +
<!--GIDEROSCST:KeyCode.MODIFIER_ALT 2-->
 +
<!--GIDEROSCST:KeyCode.MODIFIER_CTRL 4-->
 +
<!--GIDEROSCST:KeyCode.MODIFIER_META 8-->
 +
<!--GIDEROSCST:KeyCode.MODIFIER_NONE 0-->
 +
<!--GIDEROSCST:KeyCode.MODIFIER_SHIFT 1-->
 +
<!--GIDEROSCST:KeyCode.MOUSE_LEFT 1-->
 +
<!--GIDEROSCST:KeyCode.MOUSE_MIDDLE 4-->
 +
<!--GIDEROSCST:KeyCode.MOUSE_NONE 0-->
 +
<!--GIDEROSCST:KeyCode.MOUSE_RIGHT 2-->
 +
<!--GIDEROSCST:KeyCode.N 78-->
 +
<!--GIDEROSCST:KeyCode.NUM_0 48-->
 +
<!--GIDEROSCST:KeyCode.NUM_1 49-->
 +
<!--GIDEROSCST:KeyCode.NUM_2 50-->
 +
<!--GIDEROSCST:KeyCode.NUM_3 51-->
 +
<!--GIDEROSCST:KeyCode.NUM_4 52-->
 +
<!--GIDEROSCST:KeyCode.NUM_5 53-->
 +
<!--GIDEROSCST:KeyCode.NUM_6 54-->
 +
<!--GIDEROSCST:KeyCode.NUM_7 55-->
 +
<!--GIDEROSCST:KeyCode.NUM_8 56-->
 +
<!--GIDEROSCST:KeyCode.NUM_9 57-->
 +
<!--GIDEROSCST:KeyCode.O 79-->
 +
<!--GIDEROSCST:KeyCode.P 80-->
 +
<!--GIDEROSCST:KeyCode.PAGEDOWN 405-->
 +
<!--GIDEROSCST:KeyCode.PAGEUP 404-->
 +
<!--GIDEROSCST:KeyCode.Q 81-->
 +
<!--GIDEROSCST:KeyCode.R 82-->
 +
<!--GIDEROSCST:KeyCode.R1 308-->
 +
<!--GIDEROSCST:KeyCode.RIGHT 39-->
 +
<!--GIDEROSCST:KeyCode.S 83-->
 +
<!--GIDEROSCST:KeyCode.SEARCH 302-->
 +
<!--GIDEROSCST:KeyCode.SELECT 305-->
 +
<!--GIDEROSCST:KeyCode.SHIFT 16-->
 +
<!--GIDEROSCST:KeyCode.SPACE 32-->
 +
<!--GIDEROSCST:KeyCode.START 306-->
 +
<!--GIDEROSCST:KeyCode.T 84-->
 +
<!--GIDEROSCST:KeyCode.TAB 9-->
 +
<!--GIDEROSCST:KeyCode.U 85-->
 +
<!--GIDEROSCST:KeyCode.UP 38-->
 +
<!--GIDEROSCST:KeyCode.V 86-->
 +
<!--GIDEROSCST:KeyCode.W 87-->
 +
<!--GIDEROSCST:KeyCode.X 88-->
 +
<!--GIDEROSCST:KeyCode.Y 89-->
 +
<!--GIDEROSCST:KeyCode.Z 90-->
 +
<!--GIDEROSCST:KeyCode.F1 501-->
 +
<!--GIDEROSCST:KeyCode.F2 502-->
 +
<!--GIDEROSCST:KeyCode.F3 503-->
 +
<!--GIDEROSCST:KeyCode.F4 504-->
 +
<!--GIDEROSCST:KeyCode.F5 505-->
 +
<!--GIDEROSCST:KeyCode.F6 506-->
 +
<!--GIDEROSCST:KeyCode.F7 507-->
 +
<!--GIDEROSCST:KeyCode.F8 508-->
 +
<!--GIDEROSCST:KeyCode.F9 509-->
 +
<!--GIDEROSCST:KeyCode.F10 510-->
 +
<!--GIDEROSCST:KeyCode.F11 511-->
 +
<!--GIDEROSCST:KeyCode.F12 512-->
 
|}
 
|}
 +
 +
{{GIDEROS IMPORTANT LINKS}}

Latest revision as of 09:06, 23 September 2023

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 on phones/tablets

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 Constants