--- title: Window.ongamepadconnected slug: Web/API/Window/ongamepadconnected tags: - API - Event Handler - Experimental - Gamepad API - Property - Reference - Window - gamepadconnected - ongamepadconnected - 手柄 - 游戏 translation_of: Web/API/Window/ongamepadconnected ---
{{DefaultAPISidebar("Gamepad API")}}{{SeeCompatTable}}

{{domxref("Window")}} 接口的 ongamepadconnected 属性是一个事件处理程序,它将在游戏手柄连接时运行 (即当 {{event('gamepadconnected')}} 事件触发时)。

此方法响应的对象类型是 {{domxref("GamepadEvent")}}.

语法

window.ongamepadconnected = function() { ... };

示例

window.ongamepadconnected = function(event) {
  // 手柄上所有的可用按键和手柄控制元件上各轴向数值都能在此获取
  event.gamepad;
};

规范

Specification Status Comment
{{SpecName('Gamepad ', '#event-gamepadconnected', 'gamepadconnected event')}} {{Spec2('Gamepad')}} Initial definition

浏览器兼容性

{{Compat("api.Window.ongamepadconnected")}}

相关知识