Question on generating mouse events with modifier keys
Question on generating mouse events with modifier keys
- Subject: Question on generating mouse events with modifier keys
- From: Andrew Wu <email@hidden>
- Date: Mon, 29 Jun 2009 11:46:35 -0700
Hello,
I'm interested in creating a utility that can generate mouse clicks
with modifier keys (e.g. Ctrl + Primary button), ideally in python
(taking advantage of the python-cocoa bridge). This would first be
for machines running Leopard, and ideally later with Snow Leopard.
I've looked at some of the Cocoa documentation and tried some of the
examples, but b/c I'm not familiar with Cocoa development or
Objective-C a lot of it is going over my head. For instance some
references I've found include:
http://www.osxbook.com/book/bonus/chapter2/altermouse/
http://developer.apple.com/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html#//apple_ref/c/func/CGEventCreateKeyboardEvent
I've read up on CGEventCreateKeyboardEvent and CGEventCreateMouseEvent
and CGEventPost. I have tried the example in
CGEventCreateKeyboardEvent to output a 'Z' (although for me the sample
continues to output a 'z' (lower-case 'z') in python with:
from Quartz import *
event1 = CGEventCreateKeyboardEvent (None, 56, True);
event2 = CGEventCreateKeyboardEvent (None, 6, True);
event3 = CGEventCreateKeyboardEvent (None, 6, False);
event4 = CGEventCreateKeyboardEvent (None, 56, False);
I then tried creating a double-click event based upon
http://lists.apple.com/archives/quartz-dev/2008/Jun/msg00001.html but
continue to see only a single-click (verified by having a Terminal
window open with some lines populating the window. Normally a
double-click would highlight the string under the mouse cursor, but
what I've seen so far has been the mouse cursor moving to that
location only and no highlight).
Here is a snippet of what I'd tried to create the double-click event with:
evRef = []
# The lines commented out were an experimentation to send a
Ctrl+Primary mouse click
#evRef.append(CGEventCreateKeyboardEvent(None, 59, True))
evRef.append(CGEventCreateMouseEvent(None, kCGEventOtherMouseDown,
CGPointMake(720, 450), kCGMouseButtonLeft))
evRef.append(CGEventCreateMouseEvent(None, kCGEventOtherMouseUp,
CGPointMake(720, 450), kCGMouseButtonLeft))
#evRef.append(CGEventCreateKeyboardEvent(None, 59, False))
# Set double-click:
# Doesn't work?
count = 2
CGEventSetIntegerValueField(eventRef, kCGMouseEventClickState, count)
for i in range(2):
CGEventPost(kCGHIDEventTap, evRef[0])
CGEventPost(kCGHIDEventTap, evRef[1])
Any help / tips would be much appreciated. I tried searching the
Cocoa-dev list archives with terms "sending mouse events", "generate
mouse events", "CGEventCreateMouseEvent" with little success. Also,
b/c I am a new subscriber, I'm not entirely sure this is the
appropriate list to use - apologies if that is the case.
Many thanks!
Andrew
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden