使用虚拟键盘和jQuery为flash游戏触发按键

使用虚拟键盘和jQuery为flash游戏触发按键,jquery,flash,keypress,Jquery,Flash,Keypress,有没有办法通过虚拟键盘模拟flash游戏的按键 现在我有一个“虚拟键盘”,它只有一个按钮。当我单击它时,我希望它触发向上箭头的按下。但是这个事件需要在flash游戏中触发。 这是按钮: <button id="sim-up-arrow">Up</button> 遗憾的是,我的小卡车没有加速。尝试将变量“which”添加到您的事件中,也许flash游戏正在读取此字段 $('#sim-up-arrow').on('click', function() { var e

有没有办法通过虚拟键盘模拟flash游戏的按键

现在我有一个“虚拟键盘”,它只有一个按钮。当我单击它时,我希望它触发向上箭头的按下。但是这个事件需要在flash游戏中触发。 这是按钮:

<button id="sim-up-arrow">Up</button>
遗憾的是,我的小卡车没有加速。

尝试将变量“which”添加到您的事件中,也许flash游戏正在读取此字段

$('#sim-up-arrow').on('click', function() {
    var e = jQuery.Event('keypress', {keyCode: 38, which:38});
    // focus the game
    $('#game').focus();
    // trigger the up arrow key press
    $('#game').trigger(e);
}

你的flash游戏是否已经对上箭头键有反应?@Cherniv当我加载页面时,它没有反应。我必须先单击斜线对象。这就是我尝试聚焦的原因经过一点调查,似乎您需要在actionscript代码中导出一个触发键盘事件的函数,并从Javascript调用它。这似乎是不可能做到这一点与随机闪光游戏。你需要访问他们的代码。
$('#sim-up-arrow').on('click', function(){
    // create a new keypress event
    var e = jQuery.Event('keypress', {keyCode: 38});
    // focus the game
    $('#game').focus();
    // trigger the up arrow key press
    $('#game').trigger(e);
});
$('#sim-up-arrow').on('click', function() {
    var e = jQuery.Event('keypress', {keyCode: 38, which:38});
    // focus the game
    $('#game').focus();
    // trigger the up arrow key press
    $('#game').trigger(e);
}