Difference between revisions of "Event.KEY DOWN"

From GiderosMobile
 
(14 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Value:''' keyDown<br/>
'''<translate>Value</translate>:''' keyDown<br/>
+
'''Defined by:''' [[Sprite]]<br/>
'''<translate>Defined by</translate>:''' [[Special:MyLanguage/Controller|Controller]]<br/>
+
 
=== <translate>Descriptio</translate>n ===
+
=== Description ===
<translate>Button on controller was pushed down</translate>
+
This event is dispatched when a supported key is pressed. For the list of supported keys, check the '''[[KeyCode]]''' class. Modifiers can have values of:
=== <translate>Parameters</translate> ===
+
*[[KeyCode.MODIFIER_NONE]]
'''playerId''': (number) <translate>id of controller/player that pressed the button</translate><br/>
+
*[[KeyCode.MODIFIER_SHIFT]]
'''keyCode''': (number) <translate>button key code that was pressed</translate><br/>
+
*[[KeyCode.MODIFIER_CTRL]]
__NOTOC__
+
*[[KeyCode.MODIFIER_ALT]]
<languages />
+
*[[KeyCode.MODIFIER_META]]
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
 
'''<translate>Value</translate>:''' keyDown<br/>
+
=== Parameters ===
'''<translate>Defined by</translate>:''' [[Special:MyLanguage/Sprite|Sprite]]<br/>
+
'''keyCode''': (number) code of the key pressed<br/>
=== <translate>Descriptio</translate>n ===
+
'''realCode''': (number) real keyCode underneath<br/>
<translate>This event is dispatched when a supported key is pressed. For the list of supported keys, check [[Special:MyLanguage/KeyCode|KeyCode]] class.</translate>
+
'''modifiers''': (number) modifiers present, or nil if not supported<br/>
=== <translate>Parameters</translate> ===
+
 
'''keyCode''': (number) <translate>code of the key pressed.</translate><br/>
+
=== Example ===
'''realCode''': (number) <translate>real keyCode underneath</translate><br/>
+
<syntaxhighlight lang="lua">
 +
function onKeyDown(e)
 +
print(e.keyCode, e.realCode, e.modifiers)
 +
end
 +
 
 +
stage:addEventListener(Event.KEY_DOWN, onKeyDown)
 +
</syntaxhighlight>
 +
'''note''': for this event to work you need to add your sprite to the stage (scene).
 +
 
 +
{{Sprite}}

Latest revision as of 11:07, 25 September 2023

Available since: Gideros 2011.6
Value: keyDown
Defined by: Sprite

Description

This event is dispatched when a supported key is pressed. For the list of supported keys, check the KeyCode class. Modifiers can have values of:

Parameters

keyCode: (number) code of the key pressed
realCode: (number) real keyCode underneath
modifiers: (number) modifiers present, or nil if not supported

Example

function onKeyDown(e)
	print(e.keyCode, e.realCode, e.modifiers)
end

stage:addEventListener(Event.KEY_DOWN, onKeyDown)

note: for this event to work you need to add your sprite to the stage (scene).