Menu API

Category: API Reference

Access and interact with right-click context menu.

Functions

is_open

menu:is_open() -> boolean

Check if right-click menu is open.

Returns:

  • boolean - True if menu visible

bounds

menu:bounds() -> Rectangle?

Get menu boundaries.

Returns:

  • Rectangle? - Menu bounds, or nil if not open

item_count

menu:item_count() -> number

Get number of menu items.

Returns:

  • number - Number of options

items

menu:items() -> table

Get all menu items.

Returns:

  • table - Array of MenuItem objects

slot_bounds

menu:slot_bounds(slot: number) -> Rectangle?

Get bounds of a menu slot.

Parameters:

ParameterTypeRequiredDescription
slotnumberYesSlot index

Returns:

  • Rectangle? - Slot bounds

slot_center

menu:slot_center(slot: number) -> Point?

Get center point of a menu slot.

Parameters:

ParameterTypeRequiredDescription
slotnumberYesSlot index

Returns:

  • Point? - Center coordinates

find_item_index

menu:find_item_index(filter: table) -> number?

Find menu item index by filters.

Parameters:

ParameterTypeRequiredDescription
filtertableYesFilter options

Returns:

  • number? - Item index, or nil if not found

interact

menu:interact(slot: number) -> boolean

Interact with menu slot by index.

Parameters:

ParameterTypeRequiredDescription
slotnumberYesSlot index

Returns:

  • boolean - True if successful

interact_with

menu:interact_with(filter: table) -> boolean

Interact using filters.

Parameters:

ParameterTypeRequiredDescription
filtertableYesFilter options

Returns:

  • boolean - True if successful

Example:

menu:interact_with({action = "Attack"})
menu:interact_with({action_contains = "Talk"})
menu:interact_with({target = "Banker"})

Common Patterns

Simple Menu Selection

local function select_menu_option(action_text)
    if not menu:is_open() then
        return false
    end
    
    return menu:interact_with({action_contains = action_text})
end

-- Use it
select_menu_option("Attack")

Menu Option Listing

local function list_menu_options()
    if menu:is_open() then
        logger:info("=== Menu Options ===")
        local items = menu:items()
        for _, item in ipairs(items) do
            logger:info(item:index() .. ". " .. item:action() .. " -> " .. item:target())
        end
        logger:info("====================")
    end
end

Safe Menu Interaction

local function safe_interact(action_text)
    if not menu:is_open() then
        logger:warn("Menu not open")
        return false
    end
    
    -- Find the option
    local index = menu:find_item_index({action_contains = action_text})
    
    if not index then
        logger:warn("Option not found: " .. action_text)
        return false
    end
    
    -- Get center and click
    local center = menu:slot_center(index)
    if center then
        mouse:left_click(center.x, center.y)
        return true
    end
    
    return false
end

Related APIs

  • Mouse API - Mouse input