简体   繁体   中英

Communicating to USB devices in windows 7 and still use pre-existing drivers?

I'm looking to write a program to change the DPI setting on my logitech G502 mouse (My goal being to use the program with AutoHotkey to help automate a task where I switch my DPI allot and to learn a bit about USB). I'm fairly fluent in C++ , C# and python. But I'm not at all knowledgeable on USB or drivers.

So far I have: used the program USBlyser to identify a Control transfer sent to my mouse when using Logitech's software, which byte of the data corresponds to my DPI setting, and the product ID and Vendor ID of my mouse.

After looking around on the net I decided PyUSB would be a good option for communicating to my mouse. After installing libUsb for use with PyUSB I realised that this then replaces my current mouse driver and makes it unusable.

Am I just going about this all wrong? In my head all I want to do is send to my mouse the data "10 FF 0E CA 01 00 00", should I instead be somehow communicating with my existing logitech driver to do this? Or can I set-up libUsb without interfering with existing drivers?

Any help will be appreciated, cheers Bradley.

libusb doesn't interfere with anything. In PyUSB you choose to communicate directly with the device. To do this any other app holding this USB port have to be stopped. Windows driver in your mouse case.

I think it may be possible for you to push the DPI activation code while driver is still using mouse, but how, I have no idea now.

Or you may detach mouse temporarily , pass the code, and then release mouse back to Windows, hoping that DPI config wouldn't be reseted.

If that doesn't pass, you may always completely emulate mouse driver. It is very easy.

There are code samples for PyUSB on internet on how to interpret mouse data. So you do it and you pass the recognized command to OS either directly through Windows API or using PyMouse library.

In this case you do not need driver, because your program is one, and it sends to mouse whatever you want.

You have a lot of options how to do what you want.

For instance, if this is only for your local use, and there is interface already doing what you want, automate that interface using pywinauto to perform a macro to activate/disable higher DPI.

There are more possibilities.

You can replace Windows driver with your own version, which will support what you wish, thus making your own layer in mouse stack. But this is extreme.

I think you should start in order I wrote:

  1. See whether you can use PyUSB to send bytes needed without detaching mouse from OS

  2. If not, see whether detaching mouse, changing DPI, and returning mouse back to OS using PyUSB keeps the set DPI.

3.1 If not, make your own artificial driver using PyUSB and PyMouse

or

3.2 Use pywinauto to automate the existing interface to change DPI for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM