Difference between revisions of "KeyCode"

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