USB device opens Applications, then types in text field - macos

I got a letter in the mail that contained a small USB device. Here is what it loks like: http://imgur.com/a/VEtNK
When I plug it into my computer it seems to hover over the programs in my Dock and then opens one. It then types a link into a text field that is available. I originally had Skype in the dock and it defaulted to that one, strange. I removed Skype from the dock and now it opens to System Preferences.
Here's a video of what happens as I plug it in: https://www.dropbox.com/s/yuw6ggvo77rkvwh/Test1MysteryDevice.mov
Also, it does not appear like a memory stick does on my computer. I can't seem to locate it when it's plugged in. It would be cool if I could find it somehow. It would be even cooler if I could program it to do something I wanted.
Thanks, and if anyone can help out that's awesome or if you could point me to a forum/anywhere that might be able to help out, that'd be great!

Probably it self-identifies as a HID (Human Interface Device), specifically a keyboard. As soon as it is accepted as a keyboard by the OS it can send any sequence of keystrokes, and the OS will assume that it is input from a human user.

Scripting such behavior is easy using Applescript.
However automatically running a program from a USB stick when it is inserted is supposed to be impossible on OS X, as auto-run is a security risk.
Of course at the very least a custom USB device could be made to act like a mouse and keyboard, so even without autorun it's a risk to plug strange devices into your computer.
To get more info on the device you can go to System Profiler and look for the device on the USB bus.
If it is a custom device pretending to be a keyboard then it's probably hardwired to do what it does, and you probably won't be able to reprogram it; you'd need to find a manufacturer that will sell you customized devices.

Related

How to run an Applescript when a mouse is connected?

I have an Applescript that changes my mouse tracking speed that I want to run whenever I connect a mouse to my laptop. How do I do something like this? I was thinking of making it into an application and just clicking it whenever I need it, but I feel like there's a better way to do it.
This answer mentions launchd's ability to detect and launch an app when usb devices are connected. Sounds like what you are after.
Execute an application on Mac OS X when a particular type of USB device is connected?
You can get your specific product is, to use in the plist file, from System Profile->USB
Hope that helps.

Starting my app when USB device connected

I need to starting my app when our USB device connected.
My first attempt at this is a background application that pays attention to when USB devices are plugged in. When it notices our device connected, it calls ShellExecute( ) and starts our application.
This works nicely except in Windows 8. Supposing we're on the "Start" screen in Windows 8. In that situation, the application starts in the background and the start screen remains in front.
I think this is a "focus" problem since what I'm actually hoping to do is "steal focus" from the Start screen.
http://blogs.msdn.com/b/oldnewthing/archive/2009/02/20/9435239.aspx
Since my background application doesn't have focus (the Start screen has focus; besides, my application doesn't have a UI), it can't give focus away to my foreground application.
Let me say that in general, I hate focus stealing. Starting the app the user wants to use is a great help to our users.
How can I fix this problem? Maybe the answer is to programmatically ask the start screen to start my app but I don't see a way to do that:
http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/9ed23f32-0708-48a8-9ff7-5fce6dbe123f/windows-8-start-screen-api
Maybe I'm approaching this in the wrong way. Suggestions?
You're going about this the wrong way. Although you can write a program to constantly monitor the USB ports to detect when something is connected, there's no need. The OS is already doing that anyway.
Register an Autoplay handler for your device type and class. This is distinct from the old AutoRun feature, which would automatically execute programs found on an inserted file system.
You can begin with an overview of the feature from the November 2001 issue of MSDN Magazine.
Your handler will be a COM DLL. You can register the DLL as a handler, and register the handler with events you want to handle. You can either perform everything in the DLL, or you can put the bulk of the functionality in your application and just use the DLL as a proxy between the OS and your program.

How do I go about writing a windows driver for a bluetooth device?

I am looking for some advice/input on writing a device driver. I have never written one for windows before, let alone for bluetooth.
Can you recommend a book or website or something to get me started? I have the windows driver kit, and the examples therein but with out some place to start I am dead in the water.
The specifics: My friend gave me his mac Magic Mouse. I have a windows 7 machine. With the mouse set up as just a generic HID device it works ok as a two button mouse with no scroll, the motion is smooth and the acceleration what you expect in a windows mouse.
The mouse actually has a fairly good lpi resolution, making it pretty sensitive. There are mac drivers available, extracted from bootcamp. They kind of work. The cursor will randomly freeze or stop responding to the mouse's movement, which is buffered, and then leap once whatever has caused the stall stops. As an added touch the mac drivers make the cursor move like it would on a mac, with that logarithmic acceleration, that will completely throw off any windows user. With the driers you get vertical and horizontal scroll, but that's it. There is no multi touch functionality, and you can't change any of the behaviors, like acceleration. There isn't multiclutch for windows, or other 3rd party software for a multi touch mouse.
So I figured I would endeavor to make my own drivers and multi touch functionality in windows for this thing. I know mac will never support it properly under windows and windows won't write there own drivers until there is a reason.
Also if any one knows of any one else trying to do the same or similar things, point me to them.

How do I tell OS X to ignore the input from one of two connected USB mice?

I have two USB mice connected to my Mac, one of which I'm using as a scanner. I need access to the Generic X and Y data but I don't want that data to move the cursor. How, under either carbon or cocoa environments, do I tell the system to ignore the mouse as a pointing device?
Edit: after some digging I've found that I can turn off mouse position updating with the CGAssociateMouseAndMouseCursorPosition() function, but this does not allow me to specify a single mouse. Can anyone explain the OS X relationship between HID mouse devices and the cursor? There has to be a binding between the hardware and software on a device by device basis but I can't find it.
I would look into writing a basic user-space driver for the mouse.
This will allow you direct access to the mouse as a USB device. You can also take control of the device from the system for your exclusive use.
There is some documentation here:
Working With USB Device Interfaces
To get you started, the set up steps to connect to a USB device go like this (I think, my IOKit is rusty)
include < IOKit/IOKitLib.h > and < IOKit/usb/IOUSBLib.h >
find the device you are interested in using IOServiceMatching(). This lets you pick find the correct USB device based on its properties, including things like vendor ID, &c. (See the IORegistryExplorer tool screen shot below)
get a USB plugin instance (let's call it plugin) with IOCreatePlugInInterfaceForService()
use plugin from step 2 get a device interface (let's call it device) using (**plugin)->QueryInterface()
device represents a connection handle to your USB device--open it first using either (**device).USBDeviceOpen or (**device).USBDeviceOpenSeize(). from there you should be able to send/receive data.
Sounds like a lot I know.. and there might be an easier way, but this is what comes to my mind. There may be some benefits to having this level of control of the device, not sure. good luck.

Device Information from NSEvent/CGEvent

My application uses an event tap to capture keyboard events, and I'd like to know which device (i.e. which keyboard) each event comes from. Is there an sort of device-identifying information along with the CGEvent that a tap gets? I've looked at NSEvent's methods, and the various CGEventField keys, but none of them seem to be device-unique. Any help?
You might want to take a look at DDHidLib, Dave Dribin's excellent framework to work with USB HID devices independently.
http://www.dribin.org/dave/blog/archives/2007/03/19/ddhidlib_10
(not just about joysticks, so read more than the first paragraph of that blog post)
Some of the functionality of DDHidLib no longer works under Leopard, due to some security concerns at Apple regarding capturing an HID device, but if you're lucky it might provide you with what you need.
DDHidLib is neat, and in fact I rewrote parts of it for Delicious Library 2 for Leopard's newer HID APIs, and submitted the changes back to the original author -- if you write him you can get the Leopard-only sample code.
Unfortunately, the new Leopard HID APIs have the ability to peak at keyboard events as they pass by, but NOT to intercept them, so you can't build your own application-level device handler unless it's OK that the key events are also going to the AppKit, as well. (This is why there's a BONKING noise when you use a USB barcode scanner in Delicious Library 2 - I peak at the scanner and read the barcode, but then the typing is still sent to the topmost window, which doesn't want it, and beeps a lot. Sigh.)
-Wil

Resources