Re: generating the event
Re: generating the event
- Subject: Re: generating the event
- From: "Gurmit Teotia" <email@hidden>
- Date: Fri, 26 May 2006 10:54:28 +0530
It is already on. Let me describe my requirement in more detail. We have
developed an application in Flash and we are playing it using WebView in
Cocoa. Flash application display it's context menu on Control+LeftMouseDown
event. We do not want to display that menu instead we want to take some
other action in flash application. For this we decided to pass some other
event to Flash application on Control+LeftMouseDown.
To achieve this functionality we've overrided the sendEvent method of
NSWindow class some like this:
-(void)sendEvent:(NSEvent *)event
{
if (([event type]==NSLeftMouseDown) && ([event modifierFlags]&
NSControlKeyMask))
{
NSEvent *event=[NSEvent keyEventWithType:NSKeyDown
location:NSMakePoint(0,0), modifierFlags:NSShiftKeyMask|NSControlKeyMask
timestamp:0 windowNumber: [[sender window] windowNumber] context:nil
characters:@"1" charactersIgnoringModifiers:@"1" isARepeat:NO keyCode:18];
[NSApp postEvent: event: atStart:YES];
}
else
{
[super sendEvent:event];
}
}
But no keyboard event is detected by Flash application but it is detecting
keyboard events directly from keyboard.
To investigate it further I retained the actual keyboard event from keyboard
and later send it on Control+LeftMouseDown. To my suprise it works but flash
application still does not detect the Shift+Control key status it only
detect the actual keycode. i.e from Shift+Control+1 combination it only
detect 1.
Here is the code snippet
(void)sendEvent:(NSEvent *)event
{
static BOOL firstEvent=YES;
if([event type]==NSKeyDown)
{
//e is the NSEvent variable
if(firstEvent)
{
e=[event retain];
firstEvent=NO;
}
}
if (([event type]==NSLeftMouseDown) && ([event modifierFlags]&
NSControlKeyMask))
{
[NSApp postEvent:e atStart:YES];
}
else
{
[super sendEvent:event];
}
}
I appreciate responses of all you people
Regards,
Gurmit
On 5/26/06, Gregory Cooksey <email@hidden> wrote:
On May 24, 2006, at 12:06 AM, Gurmit Teotia wrote:
> I think your solution only work if the destination of your event is
> your application.
> If you want to target another application, have a look at
> CGPostKeyboardEvent() :
> http://developer.apple.com/documentation/Carbon/Reference/
> QuartzEventServicesRef/Reference/reference.html
> Yes destination of event is my application but still it is not
> working.
>
> Regards,
> Gurmit
>
You may need to turn on "Enable Access for Assistive Devices" in the
Accessibility Preference Pane.
-Greg
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden