@MateoProgramistaZaDyche , you could try to use WMI to detect the USB device when the USB device is inserted in your computer.
Here is a code example you could refer to.
using System.Management;
public Form1()
{
InitializeComponent();
backgroundWorker1.RunWorkerAsync();
TextBox.CheckForIllegalCrossThreadCalls = false;
}
private void Watcher_EventArrived(object sender, EventArrivedEventArgs e)
{
ManagementBaseObject instance = (ManagementBaseObject)e.NewEvent["TargetInstance"];
string result = "Device Name is " + instance.Properties["Name"].Value.ToString();
textBox1.Text = result;
Console.WriteLine("inserted");
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
ManagementEventWatcher watcher = new ManagementEventWatcher();
WqlEventQuery query = new WqlEventQuery("SELECT * FROM __InstanceCreationEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_USBHub'");
watcher.EventArrived += Watcher_EventArrived;
watcher.Query = query;
watcher.Start();
watcher.WaitForNextEvent();
}
Based on my test, I could detect the mouse and keyboard USB Device when I inserted the device to the computer.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.