Difference between revisions of "KeyCode"

From GiderosMobile
 
(22 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
'''Supported platforms:''' android, ios, mac, pc<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.A]]
+
'''[[KeyCode Constants]]'''
[[KeyCode.ALT]]
+
<!--GIDEROSCST:KeyCode.A 65-->
[[KeyCode.B]]
+
<!--GIDEROSCST:KeyCode.ALT 18-->
[[KeyCode.BACK]]
+
<!--GIDEROSCST:KeyCode.B 66-->
[[KeyCode.BACKSPACE]]
+
<!--GIDEROSCST:KeyCode.BACK 301-->
[[KeyCode.C]]
+
<!--GIDEROSCST:KeyCode.BACKSPACE 8-->
[[KeyCode.CENTER]]
+
<!--GIDEROSCST:KeyCode.C 67-->
[[KeyCode.CTRL]]
+
<!--GIDEROSCST:KeyCode.CENTER 304-->
[[KeyCode.D]]
+
<!--GIDEROSCST:KeyCode.CTRL 17-->
[[KeyCode.DELETE]]
+
<!--GIDEROSCST:KeyCode.D 68-->
[[KeyCode.DOWN]]
+
<!--GIDEROSCST:KeyCode.DELETE 403-->
[[KeyCode.E]]
+
<!--GIDEROSCST:KeyCode.DOWN 40-->
[[KeyCode.END]]
+
<!--GIDEROSCST:KeyCode.E 69-->
[[KeyCode.ENTER]]
+
<!--GIDEROSCST:KeyCode.END 401-->
[[KeyCode.ESC]]
+
<!--GIDEROSCST:KeyCode.ENTER 13-->
[[KeyCode.F]]
+
<!--GIDEROSCST:KeyCode.ESC 27-->
[[KeyCode.G]]
+
<!--GIDEROSCST:KeyCode.F 70-->
[[KeyCode.H]]
+
<!--GIDEROSCST:KeyCode.G 71-->
[[KeyCode.HOME]]
+
<!--GIDEROSCST:KeyCode.H 72-->
[[KeyCode.I]]
+
<!--GIDEROSCST:KeyCode.HOME 400-->
[[KeyCode.INSERT]]
+
<!--GIDEROSCST:KeyCode.I 73-->
[[KeyCode.J]]
+
<!--GIDEROSCST:KeyCode.INSERT 402-->
[[KeyCode.K]]
+
<!--GIDEROSCST:KeyCode.J 74-->
[[KeyCode.L]]
+
<!--GIDEROSCST:KeyCode.K 75-->
[[KeyCode.L1]]
+
<!--GIDEROSCST:KeyCode.L 76-->
[[KeyCode.LEFT]]
+
<!--GIDEROSCST:KeyCode.L1 307-->
[[KeyCode.M]]
+
<!--GIDEROSCST:KeyCode.LEFT 37-->
[[KeyCode.MENU]]
+
<!--GIDEROSCST:KeyCode.M 77-->
[[KeyCode.MODIFIER_ALT]]
+
<!--GIDEROSCST:KeyCode.MENU 303-->
[[KeyCode.MODIFIER_CTRL]]
+
<!--GIDEROSCST:KeyCode.MODIFIER_ALT 2-->
[[KeyCode.MODIFIER_META]]
+
<!--GIDEROSCST:KeyCode.MODIFIER_CTRL 4-->
[[KeyCode.MODIFIER_NONE]]
+
<!--GIDEROSCST:KeyCode.MODIFIER_META 8-->
[[KeyCode.MODIFIER_SHIFT]]
+
<!--GIDEROSCST:KeyCode.MODIFIER_NONE 0-->
[[KeyCode.MOUSE_LEFT]]
+
<!--GIDEROSCST:KeyCode.MODIFIER_SHIFT 1-->
[[KeyCode.MOUSE_MIDDLE]]
+
<!--GIDEROSCST:KeyCode.MOUSE_LEFT 1-->
[[KeyCode.MOUSE_NONE]]
+
<!--GIDEROSCST:KeyCode.MOUSE_MIDDLE 4-->
[[KeyCode.MOUSE_RIGHT]]
+
<!--GIDEROSCST:KeyCode.MOUSE_NONE 0-->
[[KeyCode.N]]
+
<!--GIDEROSCST:KeyCode.MOUSE_RIGHT 2-->
[[KeyCode.NUM_0]]
+
<!--GIDEROSCST:KeyCode.N 78-->
[[KeyCode.NUM_1]]
+
<!--GIDEROSCST:KeyCode.NUM_0 48-->
[[KeyCode.NUM_2]]
+
<!--GIDEROSCST:KeyCode.NUM_1 49-->
[[KeyCode.NUM_3]]
+
<!--GIDEROSCST:KeyCode.NUM_2 50-->
[[KeyCode.NUM_4]]
+
<!--GIDEROSCST:KeyCode.NUM_3 51-->
[[KeyCode.NUM_5]]
+
<!--GIDEROSCST:KeyCode.NUM_4 52-->
[[KeyCode.NUM_6]]
+
<!--GIDEROSCST:KeyCode.NUM_5 53-->
[[KeyCode.NUM_7]]
+
<!--GIDEROSCST:KeyCode.NUM_6 54-->
[[KeyCode.NUM_8]]
+
<!--GIDEROSCST:KeyCode.NUM_7 55-->
[[KeyCode.NUM_9]]
+
<!--GIDEROSCST:KeyCode.NUM_8 56-->
[[KeyCode.O]]
+
<!--GIDEROSCST:KeyCode.NUM_9 57-->
[[KeyCode.P]]
+
<!--GIDEROSCST:KeyCode.O 79-->
[[KeyCode.PAGEDOWN]]
+
<!--GIDEROSCST:KeyCode.P 80-->
[[KeyCode.PAGEUP]]
+
<!--GIDEROSCST:KeyCode.PAGEDOWN 405-->
[[KeyCode.Q]]
+
<!--GIDEROSCST:KeyCode.PAGEUP 404-->
[[KeyCode.R]]
+
<!--GIDEROSCST:KeyCode.Q 81-->
[[KeyCode.R1]]
+
<!--GIDEROSCST:KeyCode.R 82-->
[[KeyCode.RIGHT]]
+
<!--GIDEROSCST:KeyCode.R1 308-->
[[KeyCode.S]]
+
<!--GIDEROSCST:KeyCode.RIGHT 39-->
[[KeyCode.SEARCH]]
+
<!--GIDEROSCST:KeyCode.S 83-->
[[KeyCode.SELECT]]
+
<!--GIDEROSCST:KeyCode.SEARCH 302-->
[[KeyCode.SHIFT]]
+
<!--GIDEROSCST:KeyCode.SELECT 305-->
[[KeyCode.SPACE]]
+
<!--GIDEROSCST:KeyCode.SHIFT 16-->
[[KeyCode.START]]
+
<!--GIDEROSCST:KeyCode.SPACE 32-->
[[KeyCode.T]]
+
<!--GIDEROSCST:KeyCode.START 306-->
[[KeyCode.TAB]]
+
<!--GIDEROSCST:KeyCode.T 84-->
[[KeyCode.U]]
+
<!--GIDEROSCST:KeyCode.TAB 9-->
[[KeyCode.UP]]
+
<!--GIDEROSCST:KeyCode.U 85-->
[[KeyCode.V]]
+
<!--GIDEROSCST:KeyCode.UP 38-->
[[KeyCode.W]]
+
<!--GIDEROSCST:KeyCode.V 86-->
[[KeyCode.X]]
+
<!--GIDEROSCST:KeyCode.W 87-->
[[KeyCode.Y]]
+
<!--GIDEROSCST:KeyCode.X 88-->
[[KeyCode.Z]]
+
<!--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