Difference between revisions of "Event.KEY DOWN"

From GiderosMobile
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. List of supported keys '''[[KeyCode Constants]]'''.
*[[KeyCode.MODIFIER_NONE]]
 
*[[KeyCode.MODIFIER_SHIFT]]
 
*[[KeyCode.MODIFIER_CTRL]]
 
*[[KeyCode.MODIFIER_ALT]]
 
*[[KeyCode.MODIFIER_META]]
 
  
 
=== Parameters ===
 
=== Parameters ===
 +
'''type''': (String) '''keyDown'''<br/>
 
'''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:<br/>
 +
&nbsp;&nbsp; no key modifier, '''KeyCode.MODIFIER_NONE''', '''0'''<br/>
 +
&nbsp;&nbsp; ''SHIFT'' key modifier, '''KeyCode.MODIFIER_SHIFT''', '''1'''<br/>
 +
&nbsp;&nbsp; ''LEFT ALT'' modifier, '''KeyCode.MODIFIER_ALT''', '''2'''<br/>
 +
&nbsp;&nbsp; ''CONTROL'' modifier, '''KeyCode.MODIFIER_CTRL''', '''4'''<br/>
 +
&nbsp;&nbsp; ''RIGHT ALT'' modifier, '''KeyCode.MODIFIER_ALT''', '''6'''<br/>
 +
&nbsp;&nbsp; ''META'' modifier, '''KeyCode.MODIFIER_META''', '''8'''<br/>
  
 
=== Example ===
 
=== Example ===
Line 22: Line 24:
 
print(e.keyCode, e.realCode, e.modifiers)
 
print(e.keyCode, e.realCode, e.modifiers)
 
end
 
end
 
 
stage:addEventListener(Event.KEY_DOWN, onKeyDown)
 
stage:addEventListener(Event.KEY_DOWN, onKeyDown)
 
</syntaxhighlight>
 
</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}}

Revision as of 23:22, 31 July 2025

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

Description

This event is dispatched when a supported key is pressed. List of supported keys KeyCode Constants.

Parameters

type: (String) keyDown
keyCode: (number) code of the key pressed
realCode: (number) real keyCode underneath
modifiers: (number) modifiers present:
   no key modifier, KeyCode.MODIFIER_NONE, 0
   SHIFT key modifier, KeyCode.MODIFIER_SHIFT, 1
   LEFT ALT modifier, KeyCode.MODIFIER_ALT, 2
   CONTROL modifier, KeyCode.MODIFIER_CTRL, 4
   RIGHT ALT modifier, KeyCode.MODIFIER_ALT, 6
   META modifier, KeyCode.MODIFIER_META, 8

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)