开发者

Simulate key press in browser?

Is it possible to simulate key press on the browser (js, canvas, server side?), let says开发者_开发问答 I have some key presses in some data structures, left right up and down there is a flash file loaded so instead of me typing left right up and down the browser execute it and the flash reads those things? Kind of like a macro.


I'm not exactly sure if it would work on a Flash embed but you can definitely simulate keypresses by using JavaScript.

If you haven't already, you should check out jQuery. (If you want to Get Things Done, fast with JavaScript, and are new, then I would suggest to don't even bother learning JavaScript and learn jQuery instead (jQuery is a JavaScript Library, so you'd still be using/writing javascript, except with a much more powerful set of toys))

in jQuery to do a Left,Right,Up,Down would be...

<script>
$(function(){
  var left = $.Event('keypress');
  left.which = 37;
  var right = $.Event('keypress');
  right.which = 39;
  var up = $.Event('keypress');
  up.which = 38;
  var down = $.Event('keypress');
  down.which = 40;

  $('embed')
    .trigger(left)
    .trigger(right)
    .trigger(up)
    .trigger(down)
  ;
});
</script>

This might not give you exactly what you are looking for, but have a look at jQuery sendkeys extension http://bililite.com/blog/2011/01/23/improved-sendkeys/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜