keyManager

Methods
2
Fields
None

Getting one

keyManager

Methods

MethodReturnsDescription
registerKeyListener(KeyListener)()Adds keyListener (a table with keyPressed/keyReleased/keyTyped) at the end of the list, unless it is already in it. Register in `st…
unregisterKeyListener(KeyListener)()Removes keyListener from the list.

Method details

registerKeyListener

registerKeyListener: (KeyManager, KeyListener) -> ()

Adds keyListener (a table with keyPressed/keyReleased/keyTyped) at the end of the list, unless it is already in it. Register in startUp and unregister in shutDown: a listener left registered gets nothing while its plugin is stopped.

Example
local listener = {
    keyPressed = function(_self, event: AwtKeyEvent)
        if event:getKeyCode() == KeyEvent.VK_F12 then
            enabled = not enabled
        end
    end,
    keyReleased = function(_self, _event: AwtKeyEvent) end,
    keyTyped = function(_self, _event: AwtKeyEvent) end,
    isEnabledOnLoginScreen = function(_self)
        return false
    end,
    focusLost = function(_self) end,
}

function plugin:startUp()
    keyManager:registerKeyListener(listener)
end

function plugin:shutDown()
    keyManager:unregisterKeyListener(listener)
end