2011-05-25 27 views

cevap

11

NSEvent bunu yapmanın bir yolunu sağlamaz, ancak bir CGEvent oluşturabilir ve etrafında bir NSEvent sarıcısı oluşturabilirsiniz. Olay otomatik olarak imlecin mevcut yerini kullanacaktır. Bakınız CGEventCreateScrollWheelEvent. Ancak, bu olayı NSApplication'ın postEvent:atStart: kullanarak göndermesi (muhtemelen bir pencerenin tanımlanmamış olması nedeniyle) çalışmıyor. CGEvent'i doğrudan olay akışına gönderebilir veya NSEvent'i doğrudan bir görünümün scrollWheel: yöntemine gönderebilirsiniz. kod aşağıdaki

CGWheelCount wheelCount = 2; // 1 for Y-only, 2 for Y-X, 3 for Y-X-Z 
int32_t xScroll = −1; // Negative for right 
int32_t yScroll = −2; // Negative for down 
CGEventRef cgEvent = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, wheelCount, yScroll, xScroll); 

// You can post the CGEvent to the event stream to have it automatically sent to the window under the cursor 
CGEventPost(kCGHIDEventTap, cgEvent); 

NSEvent *theEvent = [NSEvent eventWithCGEvent:cgEvent]; 
CFRelease(cgEvent); 

// Or you can send the NSEvent directly to a view 
[theView scrollWheel:theEvent]; 
+0

+1 çok daha iyi cevap! –

1

Dene: benim daha

int scrollingDeltaX =... //custom value 

//if you have some NSEvent *theEvent 
    CGEventRef cgEvent = CGEventCreateCopy(theEvent.CGEvent); 

    CGEventSetIntegerValueField(cgEvent, kCGScrollWheelEventDeltaAxis2, scrollingDeltaX); 

    NSEvent *newEvent = [NSEvent eventWithCGEvent:cgEvent]; 
    CFRelease(cgEvent); 
İlgili konular