mirror of
https://github.com/evilC/AutoHotInterception.git
synced 2024-11-12 13:10:47 +00:00
Expose Handle, add methods to get ID from handle
This commit is contained in:
parent
3a06df1d72
commit
0bbb79c730
@ -36,9 +36,9 @@ namespace AutoHotInterception.Helpers
|
||||
if (handle == "") continue;
|
||||
int foundVid = 0, foundPid = 0;
|
||||
GetVidPid(handle, ref foundVid, ref foundPid);
|
||||
if (foundVid == 0 || foundPid == 0) continue;
|
||||
//if (foundVid == 0 || foundPid == 0) continue;
|
||||
|
||||
ret.Add(new DeviceInfo { Id = i, Vid = foundVid, Pid = foundPid, IsMouse = i > 10 });
|
||||
ret.Add(new DeviceInfo { Id = i, Vid = foundVid, Pid = foundPid, IsMouse = i > 10, Handle = handle});
|
||||
}
|
||||
|
||||
return ret.ToArray();
|
||||
@ -91,6 +91,7 @@ namespace AutoHotInterception.Helpers
|
||||
public bool IsMouse { get; set; }
|
||||
public int Vid { get; set; }
|
||||
public int Pid { get; set; }
|
||||
public string Handle { get; set; }
|
||||
}
|
||||
|
||||
public class ButtonState
|
||||
|
@ -271,6 +271,16 @@ namespace AutoHotInterception
|
||||
return GetDeviceId(true, vid, pid, instance);
|
||||
}
|
||||
|
||||
public int GetKeyboardIdFromHandle(string handle, int instance = 1)
|
||||
{
|
||||
return GetDeviceIdFromHandle(false, handle, instance);
|
||||
}
|
||||
|
||||
public int GetMouseIdFromHandle(string handle, int instance = 1)
|
||||
{
|
||||
return GetDeviceIdFromHandle(true, handle, instance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get Device ID from VID/PID
|
||||
/// </summary>
|
||||
@ -285,9 +295,9 @@ namespace AutoHotInterception
|
||||
var max = isMouse ? 21 : 11;
|
||||
for (var i = start; i < max; i++)
|
||||
{
|
||||
var handle = ManagedWrapper.GetHardwareStr(_deviceContext, i, 1000);
|
||||
var hardwareStr = ManagedWrapper.GetHardwareStr(_deviceContext, i, 1000);
|
||||
int foundVid = 0, foundPid = 0;
|
||||
GetVidPid(handle, ref foundVid, ref foundPid);
|
||||
GetVidPid(hardwareStr, ref foundVid, ref foundPid);
|
||||
if (foundVid != vid || foundPid != pid) continue;
|
||||
if (instance == 1)
|
||||
{
|
||||
@ -300,6 +310,33 @@ namespace AutoHotInterception
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get Device ID from Hardware String
|
||||
/// </summary>
|
||||
/// <param name="isMouse">Whether the device is a mouse or a keyboard</param>
|
||||
/// <param name="handle">The Hardware String (handle) of the device</param>
|
||||
/// <param name="instance">The instance of the VID/PID (Optional)</param>
|
||||
/// <returns></returns>
|
||||
public int GetDeviceIdFromHandle(bool isMouse, string handle, int instance = 1)
|
||||
{
|
||||
var start = isMouse ? 11 : 0;
|
||||
var max = isMouse ? 21 : 11;
|
||||
for (var i = start; i < max; i++)
|
||||
{
|
||||
var hardwareStr = ManagedWrapper.GetHardwareStr(_deviceContext, i, 1000);
|
||||
if (hardwareStr != handle) continue;
|
||||
|
||||
if (instance == 1)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
instance--;
|
||||
}
|
||||
|
||||
//ToDo: Should throw here?
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of connected devices
|
||||
/// Intended to be used called via the AHK wrapper...
|
||||
|
@ -82,6 +82,16 @@ class AutoHotInterception {
|
||||
return dev
|
||||
}
|
||||
|
||||
GetDeviceIdFromHandle(isMouse, handle, instance := 1){
|
||||
static devType := {0: "Keyboard", 1: "Mouse"}
|
||||
dev := this.Instance.GetDeviceIdFromHandle(IsMouse, handle, instance)
|
||||
if (dev == 0){
|
||||
MsgBox % "Could not get " devType[isMouse] " with Handle " handle ", Instance " instance
|
||||
ExitApp
|
||||
}
|
||||
return dev
|
||||
}
|
||||
|
||||
GetKeyboardID(VID, PID, instance := 1){
|
||||
return this.GetDeviceId(false, VID, PID, instance)
|
||||
}
|
||||
@ -90,11 +100,19 @@ class AutoHotInterception {
|
||||
return this.GetDeviceId(true, VID, PID, instance)
|
||||
}
|
||||
|
||||
GetKeyboardIdFromHandle(handle, instance := 1){
|
||||
return this.GetDeviceId(false, handle, instance)
|
||||
}
|
||||
|
||||
GetMouseIDFromHandle(handle, instance := 1){
|
||||
return this.GetDeviceId(true, handle, instance)
|
||||
}
|
||||
|
||||
GetDeviceList(){
|
||||
DeviceList := {}
|
||||
arr := this.Instance.GetDeviceList()
|
||||
for v in arr {
|
||||
DeviceList[v.id] := { ID: v.id, VID: v.vid, PID: v.pid, IsMouse: v.IsMouse }
|
||||
DeviceList[v.id] := { ID: v.id, VID: v.vid, PID: v.pid, IsMouse: v.IsMouse, Handle: v.Handle }
|
||||
}
|
||||
return DeviceList
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user