Send keyboard and mouse events to Flash Movie

℡╲_俬逩灬. 提交于 2019-12-22 10:36:25

问题


I'm looking for a way to "inject" some events into a flash movie running on a browser. I know about ActionScript's ExternalInterface.addCallback function, however I'm trying to achieve this with any "random" flash from the web. Eg. send a "SPACE" keyboard event to a youtube video.


回答1:


You can't do this to any random swf on any website because of security limitations. You need to have access to the DOM, which can only be done by Javascript Injections, unless you are the one with the swf embedded in the site, with allowScriptAccess="always" in the html template. MySpace, for example, allows you to add any random swf to the html page, but you can't do that javascript stuff because they force allowScriptAccess to always be false (among other things) to prevent any javascript/dom access.

If this is just for you to make your own life easier while browsing, you can use Firebug for Firefox. Check out this JQuerify Bookmarklet and Video, Hacking Digg with Firebug and JQuery. It shows you how to dynamically modify the webpage your on using javascript, and save those commands as shortcuts! Super cool.

So you could save a JQuerify command like:

$("#youtube_player").play();

...or whatever the api is for starting a youtube video in their html page, if that's even possible.

Hope that helps, Lance




回答2:


I tried creating a (WebKit) DOM event and sending it to the Flash OBJECT element. I also tried all of the child nodes of that element to be sure.

function fireEvent(target) {
   var evt = document.createEvent("Events");
   evt.initEvent("keypress", true, true);
   evt.view = window;
   evt.altKey = false;
   evt.ctrlKey = false;
   evt.shiftKey = false;
   evt.metaKey = false;
   evt.keyCode = 32;
   evt.charCode = ' ';
   target.dispatchEvent(evt);
}

It didn't work. My answer is: no. You can't do this, at least not from Javascript.

If you really want to do it, I think you'll have to create an application with an embedded browser control (WebKit, Gecko, etc.). Then you could call the plugin API directly to synthesize the user input events. This is how Boxee appears to works, for example.




回答3:


Unless Flash is configured to listen for the events you're trying to send it, my guess is that what you want to do isn't possible. But, as my wife will surely tell you, I'm wrong a lot.



来源:https://stackoverflow.com/questions/2314268/send-keyboard-and-mouse-events-to-flash-movie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!