I have a slightly malfunctioning mouse. My problem is that when my computer wakes up, often my mouse stops working. The light remains on and all buttons work but I cannot move my mouse until I unplug it and plug it back in.
I've written programs to fix strange issues I've had so I'm working on a program that will reset my mouse (So I don't have to manually unplug it) on wake. I tried using devcon to reset the driver using this:
Private Sub DevCon() Dim DevCon As New Process Dim err As Integer = 0 '0 = No error '1 = No device found DevCon.StartInfo.UseShellExecute = False DevCon.StartInfo.RedirectStandardOutput = True DevCon.StartInfo.RedirectStandardInput = True Try DevCon.StartInfo.FileName = "C:\devcon.exe" DevCon.StartInfo.Arguments = "restart HID_DEVICE_SYSTEM_MOUSE" DevCon.StartInfo.CreateNoWindow = True DevCon.Start() Dim sr As System.IO.StreamReader = DevCon.StandardOutput Dim line As String Do While DevCon.HasExited = False line = sr.ReadLine Select Case True Case Is = line.Contains("device(s) restarted") err = 0 Case Is = line.Contains("no matching devices found") err = 1 End Select Loop Catch ex As Exception Select Case err Case Is = 1 MsgBox("Incorrect device name.", MsgBoxStyle.Critical, Application.ProductName) End Select If ex.InnerException.InnerException.Message IsNot Nothing Then MsgBox(ex.Message & vbNewLine & vbNewLine & ex.InnerException.InnerException.Message, MsgBoxStyle.Critical, Application.ProductName) Else MsgBox(ex.Message, MsgBoxStyle.Critical, Application.ProductName) End If End Try DevCon.Dispose() End Sub
I use that with Microsoft.Win32.PowerModes enumeration, handling power mode changed to figure out if the computer has awoken. The problem is the code doesn't work as expected. It restarts the device but the problem still persists. I should probably note that the reason I use HID_DEVICE_SYSTEM_MOUSE rather than the actual hardware ID of my mouse (HID/VID_045E&PID_0047&REV_0300) results in no devices being found matching that ID.
Does anyone know of a way to fully restart the device? Like a completely shutdown of the device and driver that would definitely yield better results? Thank you!