objective c - How do I send key events to a Flash movie in WebKit? -


i trying create site-specific browser application. i've created new cocoa app, added webview window, , loading page. page contains flash movie, can controlled via keyboard. i'd wire menu commands trigger actions, presumably simulating keystrokes.

i've traversed view hierarchy , have found nsview contains movie (with class name "webhostednetscapepluginview"). i'm stuck @ point of sending keys. tried using cgeventcreatekeyboardevent() input keeps going top-level webview rather subview containing movie.

i tried [[webview window] makefirstresponder: _myview] set target input.

is cgeventcreatekeyboardevent() right function here and, if so, how target nsview?

many in advance.

my original answer work if window active. wanted work when window hidden, , came code below.

this works ordinary keys (enter, space, arrow keys, etc.). uses keycodes won't work letters , symbols might move around based on user's language , region.

and doesn't handle modifier keys command. if can figure that out gladly give them credit answer question.

// safari 4.x+ if ([[flashview classname] isequal:@"webhostednetscapepluginview"])  {     cgeventref event = cgeventcreatekeyboardevent(null, (cgkeycode)keycode, true);     [flashview keydown:[nsevent eventwithcgevent:event]];     cfrelease(event); } else  {     eventrecord event;     event.what      = keydown;      event.message   = keycode << 8;     event.modifiers = 0;       // safari 3.x     if ([flashview respondstoselector:@selector(sendevent:)]) {         [(id)flashview sendevent:(nsevent*)&event];         event.what = keyup;         [(id)flashview sendevent:(nsevent*)&event];     }      // safari 4.x     else if ([(id)flashview respondstoselector:@selector(sendevent:isdrawrect:)]) {         [(id)flashview sendevent:(nsevent *)&event isdrawrect:no];         event.what = keyup;         [(id)flashview sendevent:(nsevent *)&event isdrawrect:no];               }     else      {         nslog(@"error: unable locate event selector flash plugin");     } } 

you must first locate flash widget in browser; pass webview this.

- (nsview*)_findflashviewinview:(nsview*)view  {     nsstring* classname = [view classname];      // webhostednetscapepluginview showed in safari 4.x,     // webnetscapeplugindocumentview safari 3.x.     if ([classname isequal:@"webhostednetscapepluginview"] ||         [classname isequal:@"webnetscapeplugindocumentview"])      {         // checks make sure you've got right player         return view;     }      // okay, view isn't plugin, keep going     (nsview* subview in [view subviews])      {         nsview* result = [self _findflashviewinview:subview];         if (result) return result;     }      return nil; } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -