Difference between revisions of "Application:getKeyboardModifiers"

From GiderosMobile
m (→‎Description: fixed application in code)
m (Text replacement - "<source" to "<syntaxhighlight")
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
+
'''Available since:''' Gideros 2019.5<br/>
<languages />
+
'''Class:''' [[Application]]<br/>
  
'''<translate>Available since</translate>:''' Gideros 2019.5
+
=== Description ===
<br/>
 
'''<translate>Class</translate>:''' [[Special:MyLanguage/Application|Application]]
 
<br/>
 
=== <translate>Description</translate> ===
 
<translate>
 
 
Returns the current keyboard modifiers.
 
Returns the current keyboard modifiers.
</translate>
+
<syntaxhighlight lang="lua">
<br/>
 
<source lang="lua">
 
 
(number) = application:getKeyboardModifiers()
 
(number) = application:getKeyboardModifiers()
</source>
+
</syntaxhighlight>
=== <translate>Return values</translate> ===
+
 
'''<translate>Returns</translate>''' (number) <translate>The current modifiers bitfield.</translate>
+
=== Return values ===
<br/>
+
'''Returns''' (number) the current modifiers bitfield<br/>
<br/>
+
 
 +
=== Examples ===
 +
'''Checks if Control key is pressed'''
 +
<syntaxhighlight lang="lua">
 +
stage:addEventListener(Event.KEY_DOWN, function(e)
 +
local modifier = application:getKeyboardModifiers()
 +
print("CRTL: ", (modifier & KeyCode.MODIFIER_CTRL) > 0)
 +
end)
 +
 
 +
stage:addEventListener(Event.KEY_UP, function(e)
 +
local modifier = application:getKeyboardModifiers()
 +
print("CRTL: ", (modifier & KeyCode.MODIFIER_CTRL) > 0)
 +
end)
 +
</syntaxhighlight>
 +
 
 +
'''Checks if Control and Shift keys are pressed'''
 +
<syntaxhighlight lang="lua">
 +
stage:addEventListener(Event.KEY_DOWN, function(e)
 +
local modifier = application:getKeyboardModifiers()
 +
print("CRTL & SHIFT: ", modifier & KeyCode.MODIFIER_CTRL > 0 and modifier & KeyCode.MODIFIER_SHIFT > 0)
 +
end)
 +
 
 +
stage:addEventListener(Event.KEY_UP, function(e)
 +
local modifier = application:getKeyboardModifiers()
 +
print("CRTL & SHIFT: ", modifier & KeyCode.MODIFIER_CTRL > 0 and modifier & KeyCode.MODIFIER_SHIFT > 0)
 +
end)
 +
</syntaxhighlight>
 +
 
 +
{{Application}}

Latest revision as of 16:36, 12 July 2023

Available since: Gideros 2019.5
Class: Application

Description

Returns the current keyboard modifiers.

(number) = application:getKeyboardModifiers()

Return values

Returns (number) the current modifiers bitfield

Examples

Checks if Control key is pressed

stage:addEventListener(Event.KEY_DOWN, function(e)
	local modifier = application:getKeyboardModifiers()
	print("CRTL: ", (modifier & KeyCode.MODIFIER_CTRL) > 0)
end)

stage:addEventListener(Event.KEY_UP, function(e)
	local modifier = application:getKeyboardModifiers()
	print("CRTL: ", (modifier & KeyCode.MODIFIER_CTRL) > 0)
end)

Checks if Control and Shift keys are pressed

stage:addEventListener(Event.KEY_DOWN, function(e)
	local modifier = application:getKeyboardModifiers()
	print("CRTL & SHIFT: ", modifier & KeyCode.MODIFIER_CTRL > 0 and modifier & KeyCode.MODIFIER_SHIFT > 0)
end)

stage:addEventListener(Event.KEY_UP, function(e)
	local modifier = application:getKeyboardModifiers()
	print("CRTL & SHIFT: ", modifier & KeyCode.MODIFIER_CTRL > 0 and modifier & KeyCode.MODIFIER_SHIFT > 0)
end)