Capture mouse HID packets on windows using C++? - c++

I want to ditch Razer Synapse because it eats up to 600MB of RAM for nothing. I just want to use my macros for two additional keys found on my Razer Deathadder. I've sucessfully captured the HID packets for my Corsair K95 keyboard with C++ HID API and executed my macros, finally was able to say bye bye to iCUE. But I'm not able to open mouse as HID device. Everything should be configured properly, VID/PID, UsagePage and Usage too. But the interesting thing is that wireshark is able to capture the mouse, for me it doesn't for even when I try to open it with admin priveliges. Does somebody have any idea what I should do?
I've tried hidapitester application which is part of HIDAPI C++ library, it automatically closes the device and doesn't receive anything. If it's not possible to solve it in this way, which approach I should use to be able to capture the packets?
Thank you.

Related

Programmatically Eject USB Device while it is in use

How can i programmatically eject USB Device even if it is in use?
Scenarios:
USB device attached to the system.
We get WM_DEVICECHANGE message by "RegisterDeviceNotification" through which we can handle events like DBT_DEVICEARRIVAL, DBT_DEVICEQUERYREMOVE etc.
Now if the device is in use, if we want to eject it from explorer, it prompts as "Problem Ejecting USB Mass Storage Device "This device is currently in use. Close any programs or windows that might be using the device, and then try again."
Question: 1: How can we eject USB without any prompt while it is in use?
Question: 2: How can we get notification when the user press eject from explorer for USB device ?
Thanks in advance :)
Well, you can't mechanically eject it. So what does it mean to software-eject it? It means that Windows will prevent any further handles to be created for files or directories. As a result, it's safe to remove the USB stick afterwards
Now what does it mean that the USB stick is in use? That just means there are open handles. It doesn't make a difference whether you prevent any further handles from being created. Removing a USB stick while there's a handle open means that you risk corrupting the content on the USB stick.
Therefore, it's not a matter of wanting to ejecting the USB stick while in use. The question simply makes no sense at all.
Note that Windows already tells you what you should in fact do: Close any programs or windows that might be using the device, and then try again.
Question two similarly does not make a lot of sense either. When disk F: is gone, why should you care about the details? After all, if you had reasons to care (e.g. open file), Windows would have blocked that operation.

Controlling Firefox from C++

I am running Mozilla Firefox on Windows 7 and would like to be able to send simple commands (New Tab, Minimize, Close Tab) to it from a C++ program.
The usual question of inter-process communication, when both processes are a part of the same user program, seems to be answered by Boost.Interprocess.
But what about actually controlling the GUI window of an entirely independent application (Mozilla)?
You can use Spy++ to debug what messages each action will produce, then replicate those messages in your program.
You can use Ranorex http://www.ranorex.com, Quick Test Pro http://www8.hp.com/us/en/software-solutions/unified-functional-testing-automation/index.html#.UpvC8OJO7tw
Will give you this ability
The general answer to controlling any Windows program through its user interface is by sending it Windows messages. There are also some rather specific Windows APIs that allow you to send specific kinds of inputs directly to the keyboard, mouse or other input device.
Assuming simple requirements, you should be able to control Firefox by sending it some combination of the messages WM_[SYS]KEY[DOWN|UP], WM_[L|R]BUTTON[DOWN|UP] or similar. You may also need to use FindWindow and other things to find where to send messages. And liberal use of Spy++ to figure out what to send and where to.
Actually, what I would do is start with AutoHotKey. It can do all this stuff and then some, and it has a massive community. It's GPL so you can find out how it does stuff and there are people there to ask for help.

Low level keyboard hook doesn't work for a specific device in a specific app

I have coded up a low level keyboard hook using SetWindowsHookEX() on Windows CE 4.2 and it seems to work just fine. I am able to see key events using the keyboard and a barcode scanner in notepad and other applications as desired, but I do not see the barcode scanner events in the one application that I want to collect the keys in. I still see events from the keyboard, however, so I know that the keyboard hook is still working and in the hook chain. I have even tried inserting my hook in the chain every millisecond just to see if it would make a difference, but no dice. If I flip back to notepad, it's back to working the way I want it.
I'm not sure what the other application is doing to gain control of the scanner when that application is active that prevents it from acting like a keyboard any more. Any thoughts on this would be greatly appreciated. I've done a bunch of searches without any success. I looked into trying to use RAWINPUT, but it doesn't seem to be supported in Windows CE 4.2 from what I can tell as I don't see the user32.dll in the SDK.
There are two ways to get barcode data on most WEC devices.
The keyboard wedge (where data comes in as as keyboard events)
An OEM specific barcode reader API
If this other app your looking at uses option #2 then there is no keyboard data to retrieve, so it makes sense you wouldn't see any. That said, you might read this article to see if it offers any tips for your keyboard hook.
Functions exported by user32.dll in big Windows are generally found in coredll.dll in WEC/WEH.
-PaulH

Read Low Level Mouse Click Unix passed through PuTTY

I use PuTTY to connect to a shell (Unix Server). I can use the mouse to select Text from the CLI. Also, vim can also interact with the mouse, so I know that PuTTY does send mouse input to the server.
My problem is that I want to capture the mouse events in a C++ TUI , much like vim does (just, I will be handling them differently). I have gone through many sites, but none of them describes my problem precisely. I have a feeling that I will need xterm, but I don't know how to use it!
The best links that I found are :
How to read low level mouse click position in linux .
Weird insertion from Vim on mouse click --> How do I read this event?
A blessed UI for Jitsu --> Hats off to this guy!
Can anyone provide a sample code to read the mouse location? I can code the rest of the application then :)
It should work just fine to do this using the mouse-interface in ncurses (I'm sure that vim and other applications has no specific knowledge about how SSH/PuTTY communicates, it just picks up the mouse position as it would if it was a local connection - the sshd sorts out all the magic with translating network packets to keypresses and mouse-moves).
Here is a description of how you interface with a mouse in ncurses.

Disabling the keyboard in windows c++?

How can I completely disable the keyboard using c++ in windows? And by completely disable I mean so even Ctrl+Alt+Delete doesn't work. I did consider using a keyboard driver but I think you need to restart the computer after it is installed, but since I only need to disable it for a couple minutes that wouldn't really work.
This is not really possible.
WinLogon is designed as the one process that intercepts the Ctrl+Alt+Del key press, even when all other things hang or die.
This is the failsafe against malicious sessions, etc. So there is no obvious workaround.
Maybe a keyboard filter driver would make your request possible, but that is a real kernel-driver.
You can't disable Ctrl-Alt-Delete without removing the keyboard or replacing the keyboard driver, it generates a kernel level notification.
You could use BlockInput function. But it doesn't block CTRL + ALT + DEL.
You could install a keyboard hook and filter out the messages, but you might need to have your application as the top most window. Even then Ctrl+Alt+Del would not get filtered out.
Here's SetWindowsHookEx on MSDN
Example of Hooking the Keyboard
Ok, here goes several random suggestions. I don't have a definitite answer, but here's where I would start:
1) SetupDiRemoveDevice is probably the API you want to call. Although to call it, you'll need to make a lot of other device enumeration calls. Enumerate your HID and USB devices and find the keyboard. Start by looking for the VID/PID of the actual device for starters.
2) Delete the drivers kdbclass.sys and kbdhid.sys. You'll be fighting Windows system file to do this. I have no idea if this will work, but sounds interesting and simple.
3) Write a USB filter driver. Your driver will need to know (or be passed) the vid/pid of the device to filter on, but it might work.