Difference between revisions of "Event.KEY CHAR"

From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight")
 
(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.
+
This event is dispatched when a supported key is pressed. List of supported keys: '''[[KeyCode Constants]]'''.
  
 
=== Parameters ===
 
=== Parameters ===
 +
'''type''': (String) '''keyChar'''<br/>
 
'''text''': (String) text of the key char pressed<br/>
 
'''text''': (String) text of the key char pressed<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 19: Line 27:
 
local function onKeyChar(event)
 
local function onKeyChar(event)
 
textc:setText("key chars: "..event.text)
 
textc:setText("key chars: "..event.text)
 +
print(e.modifiers)
 
end
 
end
 
stage:addEventListener(Event.KEY_CHAR, onKeyChar)
 
stage:addEventListener(Event.KEY_CHAR, onKeyChar)
</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)
 +
 
 +
=== See also ===
 +
'''[[Event.KEY DOWN]]'''<br/>
 +
'''[[Event.KEY UP]]'''
  
 
{{Sprite}}
 
{{Sprite}}

Latest revision as of 00:05, 1 August 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)

See also

Event.KEY DOWN
Event.KEY UP