Skip to content

mouseButtonDown⚓︎

This event fires when a button on the mouse is pressed.

--- @param e mouseButtonDownEventData
local function mouseButtonDownCallback(e)
end
event.register(tes3.event.mouseButtonDown, mouseButtonDownCallback)

Tip

This event can be filtered based on the button 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⚓︎

  • button (integer): Read-only. The button index that was pressed.
  • isAltDown (boolean): Read-only. True if alt is held.
  • isControlDown (boolean): Read-only. True if control is held.
  • isShiftDown (boolean): Read-only. True if either shift key is held.
  • isSuperDown (boolean): Read-only. True if super (Windows key) is held.

Examples⚓︎

Example: Filtering out key presses that aren't equal to the bound key combination

-- An example of a simple configuration setup
local defaultConfig = {
    ---@type mwseKeyMouseCombo
    combo = {
        -- Alt + Left mouse button
        mouseButton = 0,
        isAltDown = true,
        isControlDown = false,
        isShiftDown = false,
    },
}
local config = mwse.loadConfig("myModConfig", defaultConfig)

local function registerModConfig()
    local template = mwse.mcm.createTemplate({ name = "Test Mod" })
    template:register()

    local page = template:createSideBarPage({ label = "Settings" })

    page:createKeyBinder({
        label = "My combo",
        description = "This combo does...",
        allowMouse = true,
        variable = mwse.mcm.createTableVariable({
            id = "combo",
            table = config
        }),
    })
end
event.register(tes3.event.modConfigReady, registerModConfig)


--- @param e keyDownEventData|mouseButtonDownEventData|mouseWheelEventData
local function sayHi(e)
    if not tes3.isKeyEqual({ expected = config.combo, actual = e }) then
        -- Nothing to do if the pressed combination isn't equal to our expected combination.
        return
    end

    -- Now do our logic
    tes3.messageBox("Hi!")
end

event.register(tes3.event.keyDown, sayHi)
event.register(tes3.event.mouseButtonDown, sayHi)
event.register(tes3.event.mouseWheel, sayHi)

mouseButtonUp