Share via


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 を介してアクセスするのではなく、独自のコレクションを維持することをお勧めします。

適用対象