summaryrefslogtreecommitdiff
path: root/wrapper
diff options
context:
space:
mode:
Diffstat (limited to 'wrapper')
-rw-r--r--wrapper/wrapper.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp
index f5672a1..71a8cf6 100644
--- a/wrapper/wrapper.cpp
+++ b/wrapper/wrapper.cpp
@@ -1,5 +1,6 @@
#pragma once
+#include <algorithm>
#include <type_traits>
#include <msclr\marshal_cppstd.h>
@@ -276,6 +277,30 @@ public:
}
};
+struct device_info {
+ std::wstring name;
+ std::wstring id;
+};
+
+std::vector<device_info> get_unique_device_info() {
+ std::vector<device_info> info;
+
+ rawinput_foreach_with_interface([&](const auto& dev, const WCHAR* name) {
+ info.push_back({
+ L"", // get_property_wstr(name, &DEVPKEY_Device_FriendlyName), /* doesn't work */
+ dev_id_from_interface(name)
+ });
+ });
+
+ std::sort(info.begin(), info.end(),
+ [](auto&& l, auto&& r) { return l.id < r.id; });
+ auto last = std::unique(info.begin(), info.end(),
+ [](auto&& l, auto&& r) { return l.id == r.id; });
+ info.erase(last, info.end());
+
+ return info;
+}
+
public ref struct RawInputInterop
{
static void AddHandlesFromID(String^ deviceID, List<IntPtr>^ rawInputHandles)
@@ -292,6 +317,29 @@ public ref struct RawInputInterop
throw gcnew System::Exception(gcnew String(e.what()));
}
}
+
+ static List<ValueTuple<String^, String^>>^ GetDeviceIDs()
+ {
+ try
+ {
+ auto managed = gcnew List<ValueTuple<String^, String^>>();
+
+ for (auto&& [name, id] : get_unique_device_info())
+ {
+ managed->Add(
+ ValueTuple<String^, String^>(
+ msclr::interop::marshal_as<String^>(name),
+ msclr::interop::marshal_as<String^>(id)));
+ }
+
+ return managed;
+ }
+ catch (const std::exception& e)
+ {
+ throw gcnew System::Exception(gcnew String(e.what()));
+ }
+ }
+
};
public ref struct DriverInterop