Difference between revisions of "Event.KEY CHAR"

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.
+
This event is dispatched when a supported key is pressed. List of supported keys: '''[[KeyCode Constants]]'''.
  
 
=== Parameters ===
 
=== Parameters ===
 
'''type''': (String) '''keyChar'''<br/>
 
'''type''': (String) '''keyChar'''<br/>
 
'''text''': (String) text of the key char pressed<br/>
 
'''text''': (String) text of the key char pressed<br/>
'''modifiers''': (number) indicates if a key modifier was also pressed:<br/>
+
'''modifiers''': (number) modifiers present:<br/>
&nbsp;&nbsp; '''0''': no key modifier<br/>
+
&nbsp;&nbsp; no key modifier, '''KeyCode.MODIFIER_NONE''', '''0'''<br/>
&nbsp;&nbsp; '''1''': ''SHIFT'' key modifier<br/>
+
&nbsp;&nbsp; ''SHIFT'' key modifier, '''KeyCode.MODIFIER_SHIFT''', '''1'''<br/>
&nbsp;&nbsp; '''2''': ''LEFT ALT'' modifier<br/>
+
&nbsp;&nbsp; ''LEFT ALT'' modifier, '''KeyCode.MODIFIER_ALT''', '''2'''<br/>
&nbsp;&nbsp; '''4''': ''CONTROL'' modifier<br/>
+
&nbsp;&nbsp; ''CONTROL'' modifier, '''KeyCode.MODIFIER_CTRL''', '''4'''<br/>
&nbsp;&nbsp; '''6''': ''RIGHT ALT'' modifier<br/>
+
&nbsp;&nbsp; ''RIGHT ALT'' modifier, '''KeyCode.MODIFIER_ALT''', '''6'''<br/>
 +
&nbsp;&nbsp; ''META'' modifier, '''KeyCode.MODIFIER_META''', '''8'''<br/>
  
 
=== Example ===
 
=== Example ===

Revision as of 23:19, 31 July 2025

Available since: Gideros 2016.04
Value: keyChar
Defined by: Sprite

Description

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

Parameters

type: (String) keyChar
text: (String) text of the key char pressed
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

local textc = TextField.new(nil, "key chars: ")
textc:setScale(4)
textc:setPosition(10, 130)
stage:addChild(textc)

local function onKeyChar(event)
	textc:setText("key chars: "..event.text)
	print(e.modifiers)
end
stage:addEventListener(Event.KEY_CHAR, onKeyChar)

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