Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1003329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:57:50+00:00 2026-05-16T07:57:50+00:00

I am trying to create a site-specific browser application. I’ve created a new Cocoa

  • 0

I am trying to create a site-specific browser application. I’ve created a new Cocoa app, added a WebView to my window, and am loading up the page. The page contains a Flash movie, which can be controlled via the keyboard. I’d like to wire up some menu commands to trigger the actions, presumably by simulating the keystrokes.

I’ve traversed the view hierarchy and have found the NSView that contains the movie (with class name “WebHostedNetscapePluginView”). But I’m stuck at the point of sending it keys. I tried using CGEventCreateKeyboardEvent() but the input keeps going to the top-level WebView rather than the subview containing the movie.

I tried [[webView window] makeFirstResponder: _myView] to set the target for the input.

Is CGEventCreateKeyboardEvent() the right function here and, if so, how do I get it to my target NSView?

Many thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:57:51+00:00Added an answer on May 16, 2026 at 7:57 am

    My original answer would only work if the window was active. I also wanted it to work when the window was hidden, and came up with the code below.

    This works for ordinary keys (Enter, Space, arrow keys, etc.). It uses keycodes so it won’t work for letters and symbols that might move around based on the user’s language and region.

    And it doesn’t handle modifier keys like Command. If someone can figure that out I will gladly give them credit for the answer to this question.

    // For 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;
    
         // For Safari 3.x
        if ([flashView respondsToSelector:@selector(sendEvent:)]) {
            [(id)flashView sendEvent:(NSEvent*)&event];
            event.what = keyUp;
            [(id)flashView sendEvent:(NSEvent*)&event];
        }
    
        // For 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 to locate event selector for Flash plugin");
        }
    }
    

    You must first locate the Flash widget in the browser; pass your WebView to this.

    - (NSView*)_findFlashViewInView:(NSView*)view 
    {
        NSString* className = [view className];
    
        // WebHostedNetscapePluginView showed up in Safari 4.x,
        // WebNetscapePluginDocumentView is Safari 3.x.
        if ([className isEqual:@"WebHostedNetscapePluginView"] ||
            [className isEqual:@"WebNetscapePluginDocumentView"]) 
        {
            // Do any checks to make sure you've got the right player
            return view;
        }
    
        // Okay, this view isn't a plugin, keep going
        for (NSView* subview in [view subviews]) 
        {
            NSView* result = [self _findFlashViewInView:subview];
            if (result) return result;
        }
    
        return nil;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.