在浏览器中模拟按键?

发布于 2024-10-24 09:30:21 字数 122 浏览 2 评论 0原文

是否可以在浏览器(js、canvas、服务器端?)上模拟按键操作,假设我在某些数据结构中按下了一些按键,左右上下加载了一个 flash 文件,所以我不用输入 left right浏览器上下执行它,flash读取那些东西?有点像宏。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独岁月 2024-10-31 09:30:21

我不太确定它是否适用于 Flash 嵌入,但您绝对可以使用 JavaScript 来模拟按键。

如果您还没有,您应该查看 jQuery。 (如果你想用 JavaScript 快速完成工作,并且是新手,那么我建议你甚至不要费心去学习 JavaScript,而是学习 jQuery(jQuery 是一个 JavaScript 库,所以你仍然会使用/编写 javascript) ,除了一组更强大的玩具))

在 jQuery 中执行左,右,上,下将是......

<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>

这可能不会给你你正在寻找的东西,但看看 jQuery sendkeys 扩展 < a href="http://bililite.com/blog/2011/01/23/improved-sendkeys/" rel="nofollow">http://bililite.com/blog/2011/01/23/improved-sendkeys /

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文