How to do synthetic drags
How to do synthetic drags
- Subject: How to do synthetic drags
- From: Who Am I <email@hidden>
- Date: Wed, 22 Sep 2004 02:46:05 -0400 (EDT)
Hello,
I am a full time Windows programmer (database stuff), but I have a disabled friend who was given an older USB head tracking device to use. This device moves the cursor as if it was the regular mouse and that works fine. However, she is running OS X panther, and she needs some clicking software that I offered to write for her (she can't afford to buy the ones out there). I've done a bit of Mac programming on OS X before, so the actual program is not the issue (this doesn't have to be fancy graphics or anything, just a simple Cocoa GUI).
I am having problems doing synthetic drags. I can do synthetic mouse clicks (single, double, left-button, right-button) using the CGPostMouseEvent() API in the Remote Operation framework. However, when I try to use the CGPostMouseEvent() to do a drag, it doesn't work. To see this in action, stick this code into a new project and hook up something in Interface Builder to fire the testDrag: method. It waits 2 seconds, clicks down, waits 3 more seconds, and then clicks up...ideally allowing the user to perform a drag with their head mouse during that 3 second delay (or you should be able to perform a drag just by moving (not clicking) your real mouse).
----------------------------------------
- (IBAction)testdrag: (id)poSender
{
NSTimer *loTimer = [NSTimer scheduledTimerWithTimeInterval: 2.0
target: self
selector: @selector(doMouseDown:)
userInfo:
nil
repeats: NO
];
}
- (void)doMouseDown: (NSTimer *)poTimer
{
NSBeep();
[self pressMouseButton: YES];
NSTimer *loTimer = [NSTimer scheduledTimerWithTimeInterval: 3.0
target: self
selector: @selector(doMouseUp:)
userInfo:
nil
repeats: NO
];
}
- (void)doMouseUp: (NSTimer *)poTimer
{
[self pressMouseButton: NO];
NSBeep();
}
- (void)pressMouseButton: (bool)pbDown
{
Point lzMouseLocation;
GetGlobalMouse(&lzMouseLocation);
CGPoint lzCGMouseLocation;
lzCGMouseLocation.x = lzMouseLocation.h;
lzCGMouseLocation.y = lzMouseLocation.v;
CGPostMouseEvent(lzCGMouseLocation, NO, 1, pbDown);
}
----------------------------------------
I've done a bit of research on this in my spare time, and some people have suggested using IOHIDPostEvent() instead of CGPostMouseEvent(). This was a bit harder to get to work (I copied from a sample that did some weird mach-port initialization stuff I don't really understand), but I think I got it correct. When I changed to using it, things got a bit better but still weird. I was able to perform a drag in some cases, but not in others. For example, I am now able to do a drag in the finder (for the selection rectangle) and I can draw a shape in Photoshop using the brush tool. However, I wasn't able to do other drags: dragging a Cocoa slider, increasing/decreasing the text selection-range in a text field, or dragging a file in Finder.
Does anyone know what's going on here? It seems like the simulated mouse down is working, but when the real mouse (or the head mouse) moves, those devices report that their buttons are up (which seems to stop some drag operations). Do I have to tell the system that it is in "drag state" or something so the real device input is considered "mouse drags" not "mouse moves"?
Thanks for any info,
Andrew
P.S. - sorry about the web email address, but I have a major spam problem and mailing lists are usually bad for that
Post your free ad now!
Yahoo! Canada Personals _______________________________________________
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden