Difference between revisions of "Event.KEY DOWN"

From GiderosMobile
 
(4 intermediate revisions by 2 users not shown)
Line 5: Line 5:
  
 
=== Description ===
 
=== 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:
+
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:
 
*[[KeyCode.MODIFIER_NONE]]  
 
*[[KeyCode.MODIFIER_NONE]]  
 
*[[KeyCode.MODIFIER_SHIFT]]  
 
*[[KeyCode.MODIFIER_SHIFT]]  
Line 15: Line 15:
 
'''keyCode''': (number) code of the key pressed<br/>
 
'''keyCode''': (number) code of the key pressed<br/>
 
'''realCode''': (number) real keyCode underneath<br/>
 
'''realCode''': (number) real keyCode underneath<br/>
'''modifiers''': (number) Modifiers present, or nil if not supported<br/>
+
'''modifiers''': (number) modifiers present, or nil if not supported<br/>
  
 
=== Example ===
 
=== Example ===
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
function onKeyDown(e)
 
function onKeyDown(e)
print(e.keyCode, e.realCode)
+
print(e.keyCode, e.realCode, e.modifiers)
 
end
 
end
  
 
stage:addEventListener(Event.KEY_DOWN, onKeyDown)
 
stage:addEventListener(Event.KEY_DOWN, onKeyDown)
</source>
+
</syntaxhighlight>
 
'''note''': for this event to work you need to add your sprite to the stage (scene).
 
'''note''': for this event to work you need to add your sprite to the stage (scene).
  
 
{{Sprite}}
 
{{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).