共用方式為


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存取它們。

適用於