event.connectionStateChanged

类型 布尔值
事件 inputDeviceStatus
版本 版本 2024.3703
关键词 inputDeviceStatus, connectionStateChanged

概述

如果输入设备与系统的连接发生更改,例如,从“已连接”变为“已断开”,或者从“已断开”变为“已连接”,则会将其设置为 true。你可以通过访问 event.device.connectionState 属性,轻松访问输入设备当前的连接状态。

如果输入设备与系统的当前连接未更改,则将其设置为 false。这意味着输入设备状态的某个其他方面已发生更改,例如,设备重新配置。

示例

-- Called when the status of an input device has changed.
local function onInputDeviceStatusChanged( event )
    if event.connectionStateChanged then
        print( event.device.displayName .. ": " .. event.device.connectionState )
    end
end

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