Event.KEY CHAR: Difference between revisions

From GiderosMobile
m Text replacement - "</source>" to "</syntaxhighlight>"
No edit summary
Line 8: Line 8:


=== 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) indicates if a key modifier was also pressed:<br/>
&nbsp;&nbsp; '''0''': no key modifier<br/>
&nbsp;&nbsp; '''1''': ''SHIFT'' key modifier<br/>
&nbsp;&nbsp; '''2''': ''LEFT ALT'' modifier<br/>
&nbsp;&nbsp; '''4''': ''CONTROL'' modifier<br/>
&nbsp;&nbsp; '''6''': ''RIGHT ALT'' modifier<br/>


=== Example ===
=== Example ===
Line 19: Line 26:
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)
</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 20:44, 31 July 2025

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

type: (String) keyChar
text: (String) text of the key char pressed
modifiers: (number) indicates if a key modifier was also pressed:
   0: no key modifier
   1: SHIFT key modifier
   2: LEFT ALT modifier
   4: CONTROL modifier
   6: RIGHT ALT modifier

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)