Difference between revisions of "KeyCode"
From GiderosMobile
(removed language stuff) |
(added example) |
||
Line 8: | Line 8: | ||
KeyCode table holds the key code constants. These map directly to a physical key on the keyboard. | KeyCode table holds the key code constants. These map directly to a physical key on the keyboard. | ||
− | === | + | === Examples === |
'''Listening for back button''' | '''Listening for back button''' | ||
<source lang="lua"> | <source lang="lua"> | ||
Line 16: | Line 16: | ||
end | end | ||
end) | end) | ||
+ | </source> | ||
+ | |||
+ | '''Full screen''' | ||
+ | <source lang="lua"> | ||
+ | isfullscreen = false | ||
+ | |||
+ | function setFullScreen(xbool) | ||
+ | application:setFullScreen(xbool) | ||
+ | end | ||
+ | |||
+ | function myKeysPressed() | ||
+ | self:addEventListener(Event.KEY_DOWN, function(e) | ||
+ | -- modifier | ||
+ | local modifier = application:getKeyboardModifiers() | ||
+ | local alt = (modifier & KeyCode.MODIFIER_ALT) > 0 | ||
+ | -- switch full screen | ||
+ | if alt and e.keyCode == KeyCode.ENTER then | ||
+ | isfullscreen = not isfullscreen | ||
+ | setFullScreen(isfullscreen) | ||
+ | end | ||
+ | end) | ||
+ | end | ||
</source> | </source> | ||
Revision as of 18:29, 11 December 2021
Supported platforms:
Available since: Gideros 2011.6
Inherits from: Object
Description
KeyCode table holds the key code constants. These map directly to a physical key on the keyboard.
Examples
Listening for back button
stage:addEventListener(Event.KEY_DOWN, function(event)
if event.keyCode == KeyCode.BACK then
application:exit()
end
end)
Full screen
isfullscreen = false
function setFullScreen(xbool)
application:setFullScreen(xbool)
end
function myKeysPressed()
self:addEventListener(Event.KEY_DOWN, function(e)
-- modifier
local modifier = application:getKeyboardModifiers()
local alt = (modifier & KeyCode.MODIFIER_ALT) > 0
-- switch full screen
if alt and e.keyCode == KeyCode.ENTER then
isfullscreen = not isfullscreen
setFullScreen(isfullscreen)
end
end)
end