views:

49

answers:

2

Hello I'm creating an os x application for which I try to add a remote interface. For this I need to be able to send mouse down and mouse up commands to the window of my application.

I found code with which I can successfully do this, it looks as follows:

int mask = 0x100;
NSEvent* eventMouseDown = [NSEvent mouseEventWithType:NSLeftMouseDown 
   location:p 
   modifierFlags:mask 
   timestamp:[NSDate timeIntervalSinceSystemStartup] 
   windowNumber:[w windowNumber] 
   context:[NSGraphicsContext graphicsContextWithWindow:w] 
   eventNumber:++eventCounter +42599 clickCount:1 pressure:0];
NSLog(@"Mouse down event: %@", eventMouseDown);
[[NSApplication sharedApplication] sendEvent:eventMouseDown];

I have only one problem with this code thought and this is the eventNumer parameter. As far as I found out it is a number which get increased with each event. But I cannot find a way to find the current number from where on I need to increase. The number I use there currently is just try and error and also does not seam to work always.

+1  A: 

Try just using 0 for eventNumber.

Nicholas Riley
I tried this first but if I use 0 the event does not get sendet at all. Means I don't get a reaction.
Chris
Ok, I did some more testing and now it seams to work also with 0. I don't know why it was not working before. Seams like I need to set the focus to the application correctly.
Chris
A: 

It looks like the event counter is just a serial number, so it would start at 0(plus 42599), and increase by one before each event is created. You'll just need to hang onto the last value.

I haven't tried this for myself, but it looks like the number doesn't matter so long as it is a new number every time.

jessecurry