0

我有一个使用 adobe alchemy 制作的库运行某种模拟器的 swf 文件。这个 swf 运行游戏,我们可以使用键盘控制它们,我没有重新映射键盘上按钮的选项,所以我问是否可以将此 swf 放在另一个包含重新映射按钮的接口的 swf 中键盘?如果有可能,那会影响模拟器的性能。你能给我一个如何做这些事情的例子吗?

4

1 回答 1

1

我唯一能想到的就是这样的东西,它捕获一个标准KeyboardEvent,然后发送一个新KeyboardEvent的带有重新映射的keyCode值。

目前唯一的问题是每家出版社都会派出两个KeyboardEvents。第一个将是原始版本,后者将是重新映射的版本。

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);

function keyHandler(e:KeyboardEvent):void
{
    if(!e.cancelable)
    {
        var map:Object = {
            65: 20,
            66: 13
        };

        // Set up you own event.
        // The new KeyboardEvent is cancelable, so we can track it as such.
        var kbd:KeyboardEvent = new KeyboardEvent(e.type, true, true);
        kbd.keyCode = e.keyCode;

        for(var i:String in map)
        {
            // Set the keyCode of the new KeyboardEvent to the mapped value
            // as defined above.
            if(e.keyCode === int(i)) kbd.keyCode = map[i];
        }

        stage.dispatchEvent(kbd);
    }


    // Notice that you will be notified twice of a KeyboardEvent; once for
    // the original and once for the new one with the remapped (if applicable)
    // keyCode value.
    trace(e.keyCode);
}
于 2013-04-12T02:07:42.153 回答