Difference between revisions of "KeyCode"

From GiderosMobile
 
(18 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 ===
<translate><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 /></translate>
+
 
 
=== Examples ===
 
=== Examples ===
'''Listening for back button'''<br/>
+
'''Listening for back button on phones/tablets'''
<source lang="lua">stage:addEventListener(Event.KEY_DOWN, function(event)
+
<syntaxhighlight lang="lua">
 +
stage:addEventListener(Event.KEY_DOWN, function(event)
 
     if event.keyCode == KeyCode.BACK then
 
     if event.keyCode == KeyCode.BACK then
 
         application:exit()
 
         application:exit()
 
     end
 
     end
end)</source>
+
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]]<br/>
+
'''[[KeyCode Constants]]'''
[[KeyCode.ALT]]<br/>
+
<!--GIDEROSCST:KeyCode.A 65-->
[[KeyCode.B]]<br/>
+
<!--GIDEROSCST:KeyCode.ALT 18-->
[[KeyCode.BACK]]<br/>
+
<!--GIDEROSCST:KeyCode.B 66-->
[[KeyCode.BACKSPACE]]<br/>
+
<!--GIDEROSCST:KeyCode.BACK 301-->
[[KeyCode.C]]<br/>
+
<!--GIDEROSCST:KeyCode.BACKSPACE 8-->
[[KeyCode.CENTER]]<br/>
+
<!--GIDEROSCST:KeyCode.C 67-->
[[KeyCode.CTRL]]<br/>
+
<!--GIDEROSCST:KeyCode.CENTER 304-->
[[KeyCode.D]]<br/>
+
<!--GIDEROSCST:KeyCode.CTRL 17-->
[[KeyCode.DELETE]]<br/>
+
<!--GIDEROSCST:KeyCode.D 68-->
[[KeyCode.DOWN]]<br/>
+
<!--GIDEROSCST:KeyCode.DELETE 403-->
[[KeyCode.E]]<br/>
+
<!--GIDEROSCST:KeyCode.DOWN 40-->
[[KeyCode.END]]<br/>
+
<!--GIDEROSCST:KeyCode.E 69-->
[[KeyCode.ENTER]]<br/>
+
<!--GIDEROSCST:KeyCode.END 401-->
[[KeyCode.ESC]]<br/>
+
<!--GIDEROSCST:KeyCode.ENTER 13-->
[[KeyCode.F]]<br/>
+
<!--GIDEROSCST:KeyCode.ESC 27-->
[[KeyCode.G]]<br/>
+
<!--GIDEROSCST:KeyCode.F 70-->
[[KeyCode.H]]<br/>
+
<!--GIDEROSCST:KeyCode.G 71-->
[[KeyCode.HOME]]<br/>
+
<!--GIDEROSCST:KeyCode.H 72-->
[[KeyCode.I]]<br/>
+
<!--GIDEROSCST:KeyCode.HOME 400-->
[[KeyCode.INSERT]]<br/>
+
<!--GIDEROSCST:KeyCode.I 73-->
[[KeyCode.J]]<br/>
+
<!--GIDEROSCST:KeyCode.INSERT 402-->
[[KeyCode.K]]<br/>
+
<!--GIDEROSCST:KeyCode.J 74-->
[[KeyCode.L]]<br/>
+
<!--GIDEROSCST:KeyCode.K 75-->
[[KeyCode.L1]]<br/>
+
<!--GIDEROSCST:KeyCode.L 76-->
[[KeyCode.LEFT]]<br/>
+
<!--GIDEROSCST:KeyCode.L1 307-->
[[KeyCode.M]]<br/>
+
<!--GIDEROSCST:KeyCode.LEFT 37-->
[[KeyCode.MENU]]<br/>
+
<!--GIDEROSCST:KeyCode.M 77-->
[[KeyCode.MODIFIER_ALT]]<br/>
+
<!--GIDEROSCST:KeyCode.MENU 303-->
[[KeyCode.MODIFIER_CTRL]]<br/>
+
<!--GIDEROSCST:KeyCode.MODIFIER_ALT 2-->
[[KeyCode.MODIFIER_META]]<br/>
+
<!--GIDEROSCST:KeyCode.MODIFIER_CTRL 4-->
[[KeyCode.MODIFIER_NONE]]<br/>
+
<!--GIDEROSCST:KeyCode.MODIFIER_META 8-->
[[KeyCode.MODIFIER_SHIFT]]<br/>
+
<!--GIDEROSCST:KeyCode.MODIFIER_NONE 0-->
[[KeyCode.MOUSE_LEFT]]<br/>
+
<!--GIDEROSCST:KeyCode.MODIFIER_SHIFT 1-->
[[KeyCode.MOUSE_MIDDLE]]<br/>
+
<!--GIDEROSCST:KeyCode.MOUSE_LEFT 1-->
[[KeyCode.MOUSE_NONE]]<br/>
+
<!--GIDEROSCST:KeyCode.MOUSE_MIDDLE 4-->
[[KeyCode.MOUSE_RIGHT]]<br/>
+
<!--GIDEROSCST:KeyCode.MOUSE_NONE 0-->
[[KeyCode.N]]<br/>
+
<!--GIDEROSCST:KeyCode.MOUSE_RIGHT 2-->
[[KeyCode.NUM_0]]<br/>
+
<!--GIDEROSCST:KeyCode.N 78-->
[[KeyCode.NUM_1]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_0 48-->
[[KeyCode.NUM_2]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_1 49-->
[[KeyCode.NUM_3]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_2 50-->
[[KeyCode.NUM_4]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_3 51-->
[[KeyCode.NUM_5]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_4 52-->
[[KeyCode.NUM_6]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_5 53-->
[[KeyCode.NUM_7]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_6 54-->
[[KeyCode.NUM_8]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_7 55-->
[[KeyCode.NUM_9]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_8 56-->
[[KeyCode.O]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_9 57-->
[[KeyCode.P]]<br/>
+
<!--GIDEROSCST:KeyCode.O 79-->
[[KeyCode.PAGEDOWN]]<br/>
+
<!--GIDEROSCST:KeyCode.P 80-->
[[KeyCode.PAGEUP]]<br/>
+
<!--GIDEROSCST:KeyCode.PAGEDOWN 405-->
[[KeyCode.Q]]<br/>
+
<!--GIDEROSCST:KeyCode.PAGEUP 404-->
[[KeyCode.R]]<br/>
+
<!--GIDEROSCST:KeyCode.Q 81-->
[[KeyCode.R1]]<br/>
+
<!--GIDEROSCST:KeyCode.R 82-->
[[KeyCode.RIGHT]]<br/>
+
<!--GIDEROSCST:KeyCode.R1 308-->
[[KeyCode.S]]<br/>
+
<!--GIDEROSCST:KeyCode.RIGHT 39-->
[[KeyCode.SEARCH]]<br/>
+
<!--GIDEROSCST:KeyCode.S 83-->
[[KeyCode.SELECT]]<br/>
+
<!--GIDEROSCST:KeyCode.SEARCH 302-->
[[KeyCode.SHIFT]]<br/>
+
<!--GIDEROSCST:KeyCode.SELECT 305-->
[[KeyCode.SPACE]]<br/>
+
<!--GIDEROSCST:KeyCode.SHIFT 16-->
[[KeyCode.START]]<br/>
+
<!--GIDEROSCST:KeyCode.SPACE 32-->
[[KeyCode.T]]<br/>
+
<!--GIDEROSCST:KeyCode.START 306-->
[[KeyCode.TAB]]<br/>
+
<!--GIDEROSCST:KeyCode.T 84-->
[[KeyCode.U]]<br/>
+
<!--GIDEROSCST:KeyCode.TAB 9-->
[[KeyCode.UP]]<br/>
+
<!--GIDEROSCST:KeyCode.U 85-->
[[KeyCode.V]]<br/>
+
<!--GIDEROSCST:KeyCode.UP 38-->
[[KeyCode.W]]<br/>
+
<!--GIDEROSCST:KeyCode.V 86-->
[[KeyCode.X]]<br/>
+
<!--GIDEROSCST:KeyCode.W 87-->
[[KeyCode.Y]]<br/>
+
<!--GIDEROSCST:KeyCode.X 88-->
[[KeyCode.Z]]<br/>
+
<!--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