Difference between revisions of "Event.KEY CHAR"

From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' Gideros 2016.04<br/> '''Value:''' keyChar<br/> '''Defined by:''' Sprite<br/> === Description === This event is dispatched when a supporte...")
 
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(2 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.
*[[KeyCode.MODIFIER_NONE]]
 
*[[KeyCode.MODIFIER_SHIFT]]
 
*[[KeyCode.MODIFIER_CTRL]]
 
*[[KeyCode.MODIFIER_ALT]]
 
*[[KeyCode.MODIFIER_META]]
 
  
 
=== Parameters ===
 
=== Parameters ===
'''text''': (String) text of the key pressed<br/>
+
'''text''': (String) text of the key char pressed<br/>
'''keyCode''': (number) code of the key pressed<br/>
 
'''realCode''': (number) real keyCode underneath<br/>
 
'''modifiers''': (number) modifiers present, or nil if not supported<br/>
 
  
 
=== Example ===
 
=== Example ===
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
local textc = TextField.new(nil, "key chars: ")
 
local textc = TextField.new(nil, "key chars: ")
 
textc:setScale(4)
 
textc:setScale(4)
Line 29: Line 21:
 
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).
  
 
{{Sprite}}
 
{{Sprite}}

Latest revision as of 15:26, 13 July 2023

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

Description

This event is dispatched when a supported key is pressed. For the list of supported keys, check the KeyCode class.

Parameters

text: (String) text of the key char pressed

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)
end
stage:addEventListener(Event.KEY_CHAR, onKeyChar)

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