我找了很多东西,似乎找不到满意的解决办法。我希望有人能帮忙。
当我使用jquery时,我还编写了成千上万行的javascript。所以,“纯”的JavaScript解决方案就可以了。
我正在尝试确定在鼠标指针事件中是否实际按住了控制键。就是这样,没有其他的前提条件。有人知道如何做到这一点吗,跨浏览器?
我尝试将其存储在状态变量中,方法是在按下和释放键时注意:
// BEGIN store control key status in hash_state
$().bind('keydown','ctrl',function( arg_obj_e ){
hash_state.sw_ctrldn = true;
console.debug( hash_state.sw_ctrldn );
});
$().bind('keyup','ctrl',function( arg_obj_e ){
hash_state.sw_ctrldn = false;
console.debug( hash_state.sw_ctrldn );
});
// END store control key status in hash_state
但是,这确实不起作用。如果您使用Firebug测试并观察控制台,您将看到自动重复似乎发生了,并且值切换。
我检查了mouseup事件,看是否有什么有用的地方,但是没有用:
var debugEvent = function( arg_obj_e ){
var str = '';
for ( var attr in arg_obj_e ){
str += attr + ': ' + arg_obj_e[attr] + '\n';
}
console.debug(str);
}
任何帮助都将不胜感激。