Mouse DirectInput for OSX - macos

Does anybody know of some code I can look at that tracks mouse input on a Mac like DirectInput does in Windows? I'm trying to implement "freeview" on a Mac. I've read that the HID Manager is the way to go, but I'm not sure where to start on it ...

On Mac OS X 10.5+, HID Manager is the way to go. Use ManyMouse to take away some of the pain (unfortunately, ManyMouse does not support device hotplugging, but that is trivial to implement.)

Related

Emulate an HID device on windows?

I am trying to write a program that emulates a gamepad in such a way that windows recognizes it as a gamepad, but it is actually controlled by my own code.
I have tried to create a virtual COM port and try to make windows recognize it as a gamepad, but without much luck.
Does anyone know a way to do something like this, or could maybe give me some pointers on what might be worth trying?
The HIDUSBFX2 sample driver (hidusbfx2.sys) demonstrates how to map a non-HID USB device to a HID device.
On Windows 10 there is new Virtual HID Framework (VHF) that is intended for same purpose.

macOS dedicate USB-device to specific application

I'm trying to understand if (and if so, how) it's possible to dedicate a HID (USB-card reader for NFC cards) to a specific application in macOS.
The card reader acts as a keyboard, sending the number of the card to whatever is open in macOS. I'm trying to get that USB-device locked to a specific application (e.g. firefox, chrome etc).
I really have no idea where to start looking for this. Hence I'm posting here for any help in the right direction.
Googling "Dedicate USB device to app" etc gave nothing useful.
macOS version 10.14.5 (18F132) (Mojave).
The way applications communicate to USB devices is IOKit framework. You could write it as service if you want to lock applications anywhere. And you need to know about launchd (Launch Daemon). It manages all your background service.

Gamepad and joystick support on Mac OS X in user space

I have been searching through how to do gamepad and joystick support on Mac for some days and all resources that I found seems to suggest a pre-installed driver along with using Apple's HID API, which works.
The drawback about this approach is that each joystick and gamepad will require another kernel extension to be loaded, so it can be recognized by HID manager, or at least a code less Info.plist saying it conforms to the earlier installed driver. For instance, when I have an 360 Xbox driver KEXT in house, the Xbox controller from Microsoft will work, but not the Logitech one (I tried F710).
As Apple suggests the application that uses a gamepad or joystick should be able to do themselves at user space without introducing any KEXT stuff. Is there a way to do it?
The thing I had in mind was something like using IORegistry or IOUSB API to get the device when they get plugged in (USB Prober shows it at least). Then somehow get the description of the device, then use that description to register the device as a HID one. Then the whole HID manager can be used.
Am I on the right track? Or is there any other way to do this?
Since IOKit API actually provided keywords like kHIDUsage_GD_Joystick, and there's an ForceFeedback.h library, I suppose Apple designed their HID API with joystick and force feedback in mind. That's the slim hope I had that this might work.
Some reference documentation and open source project:
Colin Munro's 360 driver
HID API Documents
DDHID Project
After revisiting this, I found out the solution to be operating directly on the file descriptors of the device. libusb is an excellent library which greatly simplify your life on this and they have Mac supported.
xboxdrv link is a great example on how to operate on file socket using libusb.
In pseudo code, it should look like this:
enumerate device
detect kernel driver and detach it if possible
open device
file off a initial transfer
wait on the callback function to handle msg and error properly
start run loop or select on fd to call libusb_event_handle
Check libusb for more info link.

How do I communicate with a GPIO USB device in OS X?

I have a USB web camera from ViMicro that contains a GPIO chip. We have a microswitch wired to one of the IO pins and can read the status of the switch on Windows using an ActiveX control that was provided by ViMicro, named exvmuvc.ax. I need to duplicate this functionality using IOKit on OS X.
USBTrace from SysNucleus displays the conversation happening between the Windows system and the USB device, but I cannot duplicate this on the Mac.
Does anyone know of a software USB sniffer, like USBTrace, that works on OS X so that I can compare the packets? Also, is anyone familiar with this particular camera chip and its GPIO subsystem, even on Linux?
You could use usbtracer from Xcode, or you can try using using USB Prober with a debug release of IOUSBFamily, this will most likely output more information than you actually want. You may want to look at qa1370 for more information.
In general though, I'd recommend you get a hardware USB analyzer, they make this sort of thing much easier.

Is there an alternative to RawInput in Mac OS X/Linux

I'm developing an application that runs on a machine that has several usb keyboards attached. Occasionally keyboards will added or removed. Each time a key is pressed, the application needs to find out which key was pressed, and which keyboard was used.
I have got a working version of the application which uses RawInput under windows. However windows can take a while to work out whats happened if you add or remove a hub or two full of keyboards, and I'm looking too see if the same can be achieved on a different OS more robustly.
Mac OS X/Cocoa would be the second choice if it is possible, but I am open to suggestions for any other platforms like linux if you can suggest a way to do it.
On Mac OS X, you can use the HID Manager to get direct visibility into which HID elements are being actuated on which devices.
That should work not just for keyboard but for all HID devices — mice, game pads, etc. — though of course you can restrict what your code pays attention to to only specific devices or devices of a specific class.
You'll need to be familiar with the concepts of USB device matching and USB Human Interface Device communication in general, but if you are then it should be fairly straightforward to get something up and running with the HID Manager on Mac OS X Leopard (10.5).

Resources