Use of kCGEventTargetProcessSerialNumber in CGEventGetDoubleValueField

1 view
Skip to first unread message

Mathieu Durandet

unread,
Oct 11, 2011, 5:58:56 AM10/11/11
to quart...@lists.apple.com
Hello,

I am currently developing a module in my app to send text to with the NSPasteboard. In order to get the app to send the text to I am using the following code in my event callback:

    [...]

    CGPoint mouseLocation = CGEventGetLocation(event);

    double targetedPSN = CGEventGetDoubleValueField(event, kCGEventTargetProcessSerialNumber);

    NSMutableData *data = [NSMutableData dataWithCapacity:0];

    float x = mouseLocation.x;

    float y = mouseLocation.y;

    [data appendBytes:&(x) length:sizeof(float)];

    [data appendBytes:&(y) length:sizeof(float)];

    [data appendBytes:&(targetedPSN) length:sizeof(double)];

    NSArray *arguments = [[NSArray alloc] initWithObjects:data, nil];

    [data release];

    [...]

The problem I am facing is that the targetedPSN I get on each mouse click is not relying my sequence of actions. In fact let's consider that the Terminal app has a psn of 1 and the TextEdit one a psn of 2. First I click in Terminal app and the above code returns me the right 1 psn. Then I click in TextEdit app and the above code still returns me a psn of 1. I need to click a second time in the TextEdit app for the event to have the right 2 psn. It's like the app needs to have the focus for the event callback to get the right psn. Am I doing something wrong ?

Thanks

--
Mathieu

Ken Thomases

unread,
Oct 11, 2011, 11:52:19 PM10/11/11
to Mathieu Durandet, quart...@lists.apple.com
On Oct 11, 2011, at 4:58 AM, Mathieu Durandet wrote:

> double targetedPSN = CGEventGetDoubleValueField(event, kCGEventTargetProcessSerialNumber);

> Am I doing something wrong ?

Well, I don't have any insight into which process is targeted for clicks on background apps, but you should be using int64_t and CGEventGetIntegerValueField() for kCGEventTargetProcessSerialNumber.

Regards,
Ken

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list (Quart...@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartz-dev/quartz-dev-garchive-50095%40googlegroups.com

This email sent to quartz-dev-g...@googlegroups.com

Mathieu Durandet

unread,
Oct 12, 2011, 3:32:22 AM10/12/11
to Ken Thomases, quart...@lists.apple.com
I tried this but this is not solving the issue. What I think is as the mouse event is "hooked" the kCGEventTargetProcessSerialNumber represents the current ProcessSerialNumber when the event was produced and not the targeted one. 

Can anyone confirm this ?
Reply all
Reply to author
Forward
0 new messages