我已经进行了大量搜索,但似乎找不到令人满意的解决方案。希望有人能够帮忙。
虽然我正在使用jQuery,但我还编写了许多千行级别的JavaScript代码。因此,“纯”JavaScript解决方案也可以。
我正在尝试确定在mouseup
事件上是否实际按下了控制键。就是这样,没有其他前提条件。 有谁知道如何可靠地跨浏览器完成这个任务吗?
我已经尝试通过记录按下和释放键时的状态变量来存储它:
// 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);
}
任何帮助都将不胜感激。