key⚓︎
The key event fires when a key up or key down input is detected. It is preferred that the keyDown and keyUp events are used instead.
--- @param e keyEventData
local function keyCallback(e)
end
event.register(tes3.event.key, keyCallback)
Tip
This event can be filtered based on the keyCode
event data.
Tip
An event can be claimed by setting e.claim
to true
, or by returning false
from the callback. Claiming the event prevents any lower priority callbacks from being called.
Event Data⚓︎
isAltDown
(boolean): Read-only. True if either alt key is held.isControlDown
(boolean): Read-only. True if either control key is held.isShiftDown
(boolean): Read-only. True if either shift key is held.isSuperDown
(boolean): Read-only. True if super (Windows key) is held.keyCode
(tes3.scanCode): Read-only. The scan code of the key that raised the event. Maps to values intes3.scanCode
table.pressed
(boolean): Read-only. True if this is a key down event, false for a key up event.
Examples⚓︎
Example: Show a Message when Ctrl-Z is Pressed
Displays a simple message when Z is pressed while control is held.
local function myOnKeyCallback(e)
if( e.pressed and e.isControlDown ) then
tes3.messageBox({ message = "You pressed Ctrl-Z, but you can't undo all your mistakes." })
end
end
-- Filter by the scan code to get Z key presses only.
event.register(tes3.event.key, myOnKeyCallback, { filter = tes3.scanCode.z } )