Difference between revisions of "KeyCode"

From GiderosMobile
 
(14 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
'''<translate>Supported platforms</translate>:''' [[File:Platform android]][[File:Platform ios]][[File:Platform mac]][[File:Platform pc]]<br/>
+
<!-- GIDEROSOBJ:KeyCode -->
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''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/>
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/>
+
'''Available since:''' Gideros 2011.6<br/>
=== <translate>Description</translate> ===
+
'''Inherits from:''' [[Object]]<br/>
<translate><br />
+
 
KeyCode table holds the key code constants. These map directly to a physical key on the keyboard.<br /></translate>
+
=== Description ===
=== <translate>Examples</translate> ===
+
KeyCode table holds the key code constants. These map directly to a physical key on the keyboard.
'''Listening for back button'''<br/>
+
 
<source lang="lua">stage:addEventListener(Event.KEY_DOWN, function(event)
+
=== Examples ===
 +
'''Listening for back button on phones/tablets'''
 +
<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%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Methods</translate> ===
+
 
 +
=== Methods ===
 +
 
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Events</translate> ===
+
=== Events ===
=== <translate>Constants</translate> ===
+
=== Constants ===
[[Special:MyLanguage/KeyCode.A|KeyCode.A]]<br/>
+
'''[[KeyCode Constants]]'''
[[Special:MyLanguage/KeyCode.ALT|KeyCode.ALT]]<br/>
+
<!--GIDEROSCST:KeyCode.A 65-->
[[Special:MyLanguage/KeyCode.B|KeyCode.B]]<br/>
+
<!--GIDEROSCST:KeyCode.ALT 18-->
[[Special:MyLanguage/KeyCode.BACK|KeyCode.BACK]]<br/>
+
<!--GIDEROSCST:KeyCode.B 66-->
[[Special:MyLanguage/KeyCode.BACKSPACE|KeyCode.BACKSPACE]]<br/>
+
<!--GIDEROSCST:KeyCode.BACK 301-->
[[Special:MyLanguage/KeyCode.C|KeyCode.C]]<br/>
+
<!--GIDEROSCST:KeyCode.BACKSPACE 8-->
[[Special:MyLanguage/KeyCode.CENTER|KeyCode.CENTER]]<br/>
+
<!--GIDEROSCST:KeyCode.C 67-->
[[Special:MyLanguage/KeyCode.CTRL|KeyCode.CTRL]]<br/>
+
<!--GIDEROSCST:KeyCode.CENTER 304-->
[[Special:MyLanguage/KeyCode.D|KeyCode.D]]<br/>
+
<!--GIDEROSCST:KeyCode.CTRL 17-->
[[Special:MyLanguage/KeyCode.DELETE|KeyCode.DELETE]]<br/>
+
<!--GIDEROSCST:KeyCode.D 68-->
[[Special:MyLanguage/KeyCode.DOWN|KeyCode.DOWN]]<br/>
+
<!--GIDEROSCST:KeyCode.DELETE 403-->
[[Special:MyLanguage/KeyCode.E|KeyCode.E]]<br/>
+
<!--GIDEROSCST:KeyCode.DOWN 40-->
[[Special:MyLanguage/KeyCode.END|KeyCode.END]]<br/>
+
<!--GIDEROSCST:KeyCode.E 69-->
[[Special:MyLanguage/KeyCode.ENTER|KeyCode.ENTER]]<br/>
+
<!--GIDEROSCST:KeyCode.END 401-->
[[Special:MyLanguage/KeyCode.ESC|KeyCode.ESC]]<br/>
+
<!--GIDEROSCST:KeyCode.ENTER 13-->
[[Special:MyLanguage/KeyCode.F|KeyCode.F]]<br/>
+
<!--GIDEROSCST:KeyCode.ESC 27-->
[[Special:MyLanguage/KeyCode.G|KeyCode.G]]<br/>
+
<!--GIDEROSCST:KeyCode.F 70-->
[[Special:MyLanguage/KeyCode.H|KeyCode.H]]<br/>
+
<!--GIDEROSCST:KeyCode.G 71-->
[[Special:MyLanguage/KeyCode.HOME|KeyCode.HOME]]<br/>
+
<!--GIDEROSCST:KeyCode.H 72-->
[[Special:MyLanguage/KeyCode.I|KeyCode.I]]<br/>
+
<!--GIDEROSCST:KeyCode.HOME 400-->
[[Special:MyLanguage/KeyCode.INSERT|KeyCode.INSERT]]<br/>
+
<!--GIDEROSCST:KeyCode.I 73-->
[[Special:MyLanguage/KeyCode.J|KeyCode.J]]<br/>
+
<!--GIDEROSCST:KeyCode.INSERT 402-->
[[Special:MyLanguage/KeyCode.K|KeyCode.K]]<br/>
+
<!--GIDEROSCST:KeyCode.J 74-->
[[Special:MyLanguage/KeyCode.L|KeyCode.L]]<br/>
+
<!--GIDEROSCST:KeyCode.K 75-->
[[Special:MyLanguage/KeyCode.L1|KeyCode.L1]]<br/>
+
<!--GIDEROSCST:KeyCode.L 76-->
[[Special:MyLanguage/KeyCode.LEFT|KeyCode.LEFT]]<br/>
+
<!--GIDEROSCST:KeyCode.L1 307-->
[[Special:MyLanguage/KeyCode.M|KeyCode.M]]<br/>
+
<!--GIDEROSCST:KeyCode.LEFT 37-->
[[Special:MyLanguage/KeyCode.MENU|KeyCode.MENU]]<br/>
+
<!--GIDEROSCST:KeyCode.M 77-->
[[Special:MyLanguage/KeyCode.MODIFIER_ALT|KeyCode.MODIFIER_ALT]]<br/>
+
<!--GIDEROSCST:KeyCode.MENU 303-->
[[Special:MyLanguage/KeyCode.MODIFIER_CTRL|KeyCode.MODIFIER_CTRL]]<br/>
+
<!--GIDEROSCST:KeyCode.MODIFIER_ALT 2-->
[[Special:MyLanguage/KeyCode.MODIFIER_META|KeyCode.MODIFIER_META]]<br/>
+
<!--GIDEROSCST:KeyCode.MODIFIER_CTRL 4-->
[[Special:MyLanguage/KeyCode.MODIFIER_NONE|KeyCode.MODIFIER_NONE]]<br/>
+
<!--GIDEROSCST:KeyCode.MODIFIER_META 8-->
[[Special:MyLanguage/KeyCode.MODIFIER_SHIFT|KeyCode.MODIFIER_SHIFT]]<br/>
+
<!--GIDEROSCST:KeyCode.MODIFIER_NONE 0-->
[[Special:MyLanguage/KeyCode.MOUSE_LEFT|KeyCode.MOUSE_LEFT]]<br/>
+
<!--GIDEROSCST:KeyCode.MODIFIER_SHIFT 1-->
[[Special:MyLanguage/KeyCode.MOUSE_MIDDLE|KeyCode.MOUSE_MIDDLE]]<br/>
+
<!--GIDEROSCST:KeyCode.MOUSE_LEFT 1-->
[[Special:MyLanguage/KeyCode.MOUSE_NONE|KeyCode.MOUSE_NONE]]<br/>
+
<!--GIDEROSCST:KeyCode.MOUSE_MIDDLE 4-->
[[Special:MyLanguage/KeyCode.MOUSE_RIGHT|KeyCode.MOUSE_RIGHT]]<br/>
+
<!--GIDEROSCST:KeyCode.MOUSE_NONE 0-->
[[Special:MyLanguage/KeyCode.N|KeyCode.N]]<br/>
+
<!--GIDEROSCST:KeyCode.MOUSE_RIGHT 2-->
[[Special:MyLanguage/KeyCode.NUM_0|KeyCode.NUM_0]]<br/>
+
<!--GIDEROSCST:KeyCode.N 78-->
[[Special:MyLanguage/KeyCode.NUM_1|KeyCode.NUM_1]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_0 48-->
[[Special:MyLanguage/KeyCode.NUM_2|KeyCode.NUM_2]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_1 49-->
[[Special:MyLanguage/KeyCode.NUM_3|KeyCode.NUM_3]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_2 50-->
[[Special:MyLanguage/KeyCode.NUM_4|KeyCode.NUM_4]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_3 51-->
[[Special:MyLanguage/KeyCode.NUM_5|KeyCode.NUM_5]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_4 52-->
[[Special:MyLanguage/KeyCode.NUM_6|KeyCode.NUM_6]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_5 53-->
[[Special:MyLanguage/KeyCode.NUM_7|KeyCode.NUM_7]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_6 54-->
[[Special:MyLanguage/KeyCode.NUM_8|KeyCode.NUM_8]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_7 55-->
[[Special:MyLanguage/KeyCode.NUM_9|KeyCode.NUM_9]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_8 56-->
[[Special:MyLanguage/KeyCode.O|KeyCode.O]]<br/>
+
<!--GIDEROSCST:KeyCode.NUM_9 57-->
[[Special:MyLanguage/KeyCode.P|KeyCode.P]]<br/>
+
<!--GIDEROSCST:KeyCode.O 79-->
[[Special:MyLanguage/KeyCode.PAGEDOWN|KeyCode.PAGEDOWN]]<br/>
+
<!--GIDEROSCST:KeyCode.P 80-->
[[Special:MyLanguage/KeyCode.PAGEUP|KeyCode.PAGEUP]]<br/>
+
<!--GIDEROSCST:KeyCode.PAGEDOWN 405-->
[[Special:MyLanguage/KeyCode.Q|KeyCode.Q]]<br/>
+
<!--GIDEROSCST:KeyCode.PAGEUP 404-->
[[Special:MyLanguage/KeyCode.R|KeyCode.R]]<br/>
+
<!--GIDEROSCST:KeyCode.Q 81-->
[[Special:MyLanguage/KeyCode.R1|KeyCode.R1]]<br/>
+
<!--GIDEROSCST:KeyCode.R 82-->
[[Special:MyLanguage/KeyCode.RIGHT|KeyCode.RIGHT]]<br/>
+
<!--GIDEROSCST:KeyCode.R1 308-->
[[Special:MyLanguage/KeyCode.S|KeyCode.S]]<br/>
+
<!--GIDEROSCST:KeyCode.RIGHT 39-->
[[Special:MyLanguage/KeyCode.SEARCH|KeyCode.SEARCH]]<br/>
+
<!--GIDEROSCST:KeyCode.S 83-->
[[Special:MyLanguage/KeyCode.SELECT|KeyCode.SELECT]]<br/>
+
<!--GIDEROSCST:KeyCode.SEARCH 302-->
[[Special:MyLanguage/KeyCode.SHIFT|KeyCode.SHIFT]]<br/>
+
<!--GIDEROSCST:KeyCode.SELECT 305-->
[[Special:MyLanguage/KeyCode.SPACE|KeyCode.SPACE]]<br/>
+
<!--GIDEROSCST:KeyCode.SHIFT 16-->
[[Special:MyLanguage/KeyCode.START|KeyCode.START]]<br/>
+
<!--GIDEROSCST:KeyCode.SPACE 32-->
[[Special:MyLanguage/KeyCode.T|KeyCode.T]]<br/>
+
<!--GIDEROSCST:KeyCode.START 306-->
[[Special:MyLanguage/KeyCode.TAB|KeyCode.TAB]]<br/>
+
<!--GIDEROSCST:KeyCode.T 84-->
[[Special:MyLanguage/KeyCode.U|KeyCode.U]]<br/>
+
<!--GIDEROSCST:KeyCode.TAB 9-->
[[Special:MyLanguage/KeyCode.UP|KeyCode.UP]]<br/>
+
<!--GIDEROSCST:KeyCode.U 85-->
[[Special:MyLanguage/KeyCode.V|KeyCode.V]]<br/>
+
<!--GIDEROSCST:KeyCode.UP 38-->
[[Special:MyLanguage/KeyCode.W|KeyCode.W]]<br/>
+
<!--GIDEROSCST:KeyCode.V 86-->
[[Special:MyLanguage/KeyCode.X|KeyCode.X]]<br/>
+
<!--GIDEROSCST:KeyCode.W 87-->
[[Special:MyLanguage/KeyCode.Y|KeyCode.Y]]<br/>
+
<!--GIDEROSCST:KeyCode.X 88-->
[[Special:MyLanguage/KeyCode.Z|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