Difference between revisions of "Application:getKeyboardModifiers"

From GiderosMobile
(added example from rrraptor)
(added another example)
Line 11: Line 11:
 
'''Returns''' (number) the current modifiers bitfield<br/>
 
'''Returns''' (number) the current modifiers bitfield<br/>
  
=== Example ===
+
=== Examples ===
 
'''Checks if Control key is pressed'''
 
'''Checks if Control key is pressed'''
 
<source lang="lua">
 
<source lang="lua">
Line 22: Line 22:
 
local modifier = application:getKeyboardModifiers()
 
local modifier = application:getKeyboardModifiers()
 
print("CRTL: ", (modifier & KeyCode.MODIFIER_CTRL) > 0)
 
print("CRTL: ", (modifier & KeyCode.MODIFIER_CTRL) > 0)
 +
end)
 +
</source>
 +
 +
'''Checks if Control and Shift keys are pressed'''
 +
<source 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)
 
end)
 
</source>
 
</source>
  
 
{{Application}}
 
{{Application}}

Revision as of 04:56, 7 March 2021

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)