Difference between revisions of "Application:getKeyboardModifiers"

From GiderosMobile
(added example from rrraptor)
Line 1: Line 1:
 
'''Available since:''' Gideros 2019.5<br/>
 
'''Available since:''' Gideros 2019.5<br/>
'''Class:''' [[Application|Application]]<br/>
+
'''Class:''' [[Application]]<br/>
  
 
=== Description ===
 
=== Description ===
 
Returns the current keyboard modifiers.
 
Returns the current keyboard modifiers.
 
 
<source lang="lua">
 
<source lang="lua">
 
(number) = application:getKeyboardModifiers()
 
(number) = application:getKeyboardModifiers()
Line 10: Line 9:
  
 
=== Return values ===
 
=== Return values ===
'''Returns''' (number) The current modifiers bitfield.
+
'''Returns''' (number) the current modifiers bitfield<br/>
 +
 
 +
=== Example ===
 +
'''Checks if Control key is pressed'''
 +
<source lang="lua">
 +
stage:addEventListener(Event.KEY_DOWN, function(e)
 +
local mod = application:getKeyboardModifiers()
 +
print("CRTL: ", (mod & KeyCode.MODIFIER_CTRL) > 0)
 +
end)
 +
 
 +
stage:addEventListener(Event.KEY_UP, function(e)
 +
local mod = application:getKeyboardModifiers()
 +
print("CRTL: ", (mod & KeyCode.MODIFIER_CTRL) > 0)
 +
end)
 +
</source>
  
 
{{Application}}
 
{{Application}}

Revision as of 22:00, 20 January 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

Example

Checks if Control key is pressed

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

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