object.isConnected

类型 布尔值
对象 InputDevice
修订版本 版本 2024.3703
关键词 设备,输入,isConnected

概述

确定输入设备当前是否连接到系统并可以提供输入事件。

如果输入设备当前可用,则返回 true。在这种情况下,connectionState 属性将处于“已连接”状态。

如果输入设备不可用且无法提供输入事件,则返回 false。在这种情况下,connectionState 属性将处于“已断开连接”、“正在断开连接”或“正在连接”状态。

示例

-- Called when the status of an input device has changed.
local function onInputDeviceStatusChanged( event )
    if event.connectionStateChanged then
        if event.device.isConnected then
            -- Device has been connected.
            -- If was once disconnected, then you should resume the game.
        else
            -- Connection has been lost.
            -- You may want to pause the game and warn the user in this case.
        end
    end
end

-- Set up the above function to receive input device status change events.
Runtime:addEventListener( "inputDeviceStatus", onInputDeviceStatusChanged )