forwardCurrentKeyEventToHost


#1

I am trying to address the keypresses insanity in the VST version of my plugin and have noticed forwardCurrentKeyEventToHost does not work with Carbon hosts.  The event doesn't show up in the host. 

It seems someone else had this problem writing a Cocoa plug-in for Photoshop (Carbon):

http://lists.apple.com/archives/cocoa-dev/2009/Aug/msg00672.html

 

I thought I would check here first though to see if anyone had a solution or thoughts about this...

 

-Steve


#2

The problem is that Carbon apps won't see the event if you put it back on the event queue the way forwardCurrentKeyEventToHost was.  In case anyone is interested, here is the fix:

In juce_VST_Wrapper.mm, forwardCurrentKeyEventToHost, change:

    [NSApp postEvent: [NSApp currentEvent] atStart: YES];

to this:

    [[NSOperationQueue mainQueue] addOperationWithBlock:^{

        [NSApp postEvent: [NSApp currentEvent] atStart: YES];

    }];

This should probably go into JUCE - hope it helps someone.

-Steve


#3

Thanks - that's really interesting... But I'm a bit mystified about why it'd make any difference.. Why would posting the event asynchronously be different to just posting it immediately? Surely either way it'll end up on the queue?


#4

..ok I think your suggestion is probably doing entirely the wrong thing, or the right thing for some unknown reason:

When the block gets invoked asynchronously, it'll call [NSApp currentEvent], but that won't return the key event that was current at the time when forwardCurrentKeyEventToHost got called. It'll return some kind of callback event, or some other random event that happened since the callback, or even nil..  (??)

Surely what you meant was this:

NSEvent* e = [NSApp currentEvent];

[[NSOperationQueue mainQueue] addOperationWithBlock:^{

    [NSApp postEvent: e atStart: YES];

}];

..but even that makes no sense to me!


#5

From what I understand the reason the event doesn't make it to the host relates to how Carbon apps are fed events versus Cocoa apps.  The link I posted had an explanation.

 

Your code is definitely the better way to go - perhaps mine was working because it fired before another event came along.

 

Thanks!

Steve


#6

Hmm. Ok, thanks.

I've checked in some changes now - I'd be keen to know if they work for you!