开发者

Send silent keys to Flash Object

开发者 https://www.devze.com 2023-02-18 22:02 出处:网络
I\'m basically trying to send a keypress to a Flash Object. Essentially I have a Win32Com instance of Internet Explorer and I have a Flash Object taken from the Internet Explorer document that I have

I'm basically trying to send a keypress to a Flash Object. Essentially I have a Win32Com instance of Internet Explorer and I have a Flash Object taken from the Internet Explorer document that I have loaded.

Is there any way to send keystrokes to this Flash Object without actually pressing the keys?

Please allow me to clarify: T开发者_JAVA百科his is not my Flash application, it is a Flash application published onto the web in .swf form.


You can simulate keypresses by just dispatching a KeyboardEvent within your app:

public function Main() 
{
    // add a listener to our stage
    this.stage.addEventListener( KeyboardEvent.KEY_DOWN, this._onKeyDown );

    // mimics an event for an 'a' key press
    var e:KeyboardEvent = new KeyboardEvent( KeyboardEvent.KEY_DOWN, true, false, 97, 65 );
    this.dispatchEvent( e );
}

// called when a key is pressed
private function _onKeyDown( e:KeyboardEvent ):void
{
    trace( "Key pressed! " + e.keyCode );
    trace( e.keyCode + " = keycode" );
    trace( e.keyLocation + " = key location" );
    trace( e.charCode + " = char code" );
}

Check out the KeyboardEvent class for more info: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/KeyboardEvent.html

If you want to fire this from your browser, then you can set up an ExternalInterface call to call your flash function that will fire off the event. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html


On Windows, you can generate input and send it to OS with SendInput function. Input is generated on system level as if user is pressing keys or using mouse, so browser must be in focus to get input.


***UPDATE... AGAIN*** Okay so I think I have the real answer to your question here. Check out this documentation:

http://livedocs.adobe.com/flex/3/html/help.html?content=19_External_Interface_10.html

You'll want to use the axShockwaveFlash.FlashCall interface.

***UPDATE*** Found this link:

Get instance of Excel application with C# by Handle

Explains how to fetch a reference to an active application instance.

***ORIGINAL POST*** I agree with alxx this is something you'll have to do natively and I don't know that it will be all that easy to do. You'll have to grab the flash instance somehow, and I'm not sure how difficult that is going to be there are a lot of variables at play to account for. However, I can say it is possible to do and here is some documentation on how to do this with various languages (C#, VC++ etc):

http://msdn.microsoft.com/en-us/library/ms171548.aspx

And here is a blog post of mine on how to interface with the flash control in C# (at least to give you an idea):

http://blog.ascensionsystems.ca/?p=153

There is a link to the source code as well available on SVN. This isn't the greatest answer in that I'm not offering any exact method but I hope this is a good start for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消