我查了很多资料,似乎找不到满意的解决方案。我希望有人能帮帮忙。
当我使用 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);
}
任何帮助,将不胜感激。