是否有脚本模拟控件的按键顺序? [英] Have a script simulate a control, keypress sequence?

查看:104
本文介绍了是否有脚本模拟控件的按键顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索并发现我可以使用jQuery模拟按键事件,但是我对jQuery的了解很差,我没有得到确切的结果.

I've searched and discovered that I can simulate a keypress event using jQuery, but my knowledge about jQuery is poor and I didn't get how exactly.

所以我有一个Greasemonkey脚本,可以在2个标签中管理2个不同的网页.
我想模拟/自动执行 Ctrl Shift Tab 自动返回到上一个选项卡,这样我可以更改Firefox.

So I have a Greasemonkey script which manages 2 different webpages in 2 tabs.
I'd like to simulate/auto-execute CtrlShiftTab to go back to the previous tab automatically, this way I could change tabs in Firefox.

问题在于它不仅是简单的按键,我还需要模拟 Ctrl Shift 部分.

The problem is that it's not only a plain keypress, I need to simulate a Ctrl and Shift parts too.

我已将其添加到脚本中:

I've added this to my script:

// @require        http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js

并尝试:

function testEvents(){
var press = jQuery.Event("keypress");
press.which = 9;
$("whatever").trigger(press.ctrlKey + press.shiftKey + press.which);

}

没有成功.

我看过的一些链接: 是否可以通过编程方式模拟按键事件?模拟jquery ,然后 http://forum.jquery.com/topic/simulating-keypress-events

Some links I've seen: Is it possible to simulate key press events programmatically?, simulate jquery, and http://forum.jquery.com/topic/simulating-keypress-events

推荐答案

JavaScript无法通过模拟快捷键"按键事件来触发默认行为.

JavaScript cannot be used to trigger a default behavior by simulating "shortcut" key events.

由于jQuery是编写JavaScript代码的另一种方式,因此该限制也适用.
而且,由于Greasemonkey脚本基于JavaScript,除了GM_*方法之外没有其他功能,因此无法编写用于切换选项卡的User脚本.

Since jQuery is just a different way to write JavaScript code, the restriction also applies.
And, because Greasemonkey scripts are based on JavaScript, without extra functionality besides the GM_* methods, it is not possible to write a User script which switches tabs.

这篇关于是否有脚本模拟控件的按键顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆