RawGameController.RawGameControllerAdded 事件

定义

连接新的原始游戏控制器时发出信号。

// Register
static event_token RawGameControllerAdded(EventHandler<RawGameController> const& handler) const;

// Revoke with event_token
static void RawGameControllerAdded(event_token const* cookie) const;

// Revoke with event_revoker
static RawGameController::RawGameControllerAdded_revoker RawGameControllerAdded(auto_revoke_t, EventHandler<RawGameController> const& handler) const;
public static event System.EventHandler<RawGameController> RawGameControllerAdded;
function onRawGameControllerAdded(eventArgs) { /* Your code */ }
Windows.Gaming.Input.RawGameController.addEventListener("rawgamecontrolleradded", onRawGameControllerAdded);
Windows.Gaming.Input.RawGameController.removeEventListener("rawgamecontrolleradded", onRawGameControllerAdded);
- or -
Windows.Gaming.Input.RawGameController.onrawgamecontrolleradded = onRawGameControllerAdded;
Public Shared Custom Event RawGameControllerAdded As EventHandler(Of RawGameController) 

事件类型

示例

以下示例开始跟踪已添加的原始游戏控制器。

#include <winrt/Windows.Gaming.Input.h>
using namespace winrt;
using namespace Windows::Gaming::Input;
...
std::vector<RawGameController> m_myRawGameControllers;
...
RawGameController::RawGameControllerAdded([this](IInspectable const& /* sender */, RawGameController const& args)
    {
        m_myRawGameControllers.push_back(args);
    });
// `myRawGameControllers` is a `Vector<RawGameController^>` that contains the raw game controllers that your game is tracking.
RawGameController::RawGameControllerAdded += ref new EventHandler<RawGameController^>(
		[] (Platform::Object^, RawGameController^ args)
{
    // This code assumes that you're interested in all new raw game controllers.
    myRawGameControllers->Append(args);
});

注解

若要识别已添加的控制器,请使用 RawGameController.RawGameControllers 查询连接的控制器列表。 但是,由于你可能只对某些连接的原始游戏控制器感兴趣,因此我们建议你维护自己的集合,而不是通过 RawGameControllers 访问它们。

适用于