object:getAxes()

类型 函数
对象 InputDevice
返回值 数组,包含 InputAxis
修订 版本 2024.3703
关键词 设备,输入,getAxes

概述

获取设备上所有可用轴输入的信息。此信息可用于检测设备的功能,例如是否有模拟操纵杆可用。

返回值

返回一个包含 InputAxis 表的数组,提供有关设备上每个可用轴输入的信息。

如果输入设备没有任何轴输入,则返回一个空数组。键盘通常就是这种情况。

示例

-- Fetch all input devices currently connected to the system.
local inputDevices = system.getInputDevices()

-- Traverse all input devices.
for deviceIndex = 1, #inputDevices do
    -- Fetch the input device's axes.
    local inputAxes = inputDevices[deviceIndex]:getAxes()
    if #inputAxes > 0 then
        -- Print all available axes to the log.
        for axisIndex = 1, #inputAxes do
            print(inputAxes[axisIndex].descriptor)
        end
    else
        -- Device does not have any axes.
        print(inputDevices[deviceIndex].descriptor .. ": No axes found.")
    end
end