繁体   English   中英

如何跟踪一个按钮的点击,然后是另一个?

[英]How to track clicks of one button and then another?

我需要跟踪点击大写锁定然后键盘快捷键 ctrl + alt,即先点击大写锁定然后点击键盘快捷键这里是一个例子

if (e.code == "CapsLock") {
        if (e.ctrlKey && e.keyCode == 18) {
          alert();
        }
      }

但此代码不起作用

我使用这样的函数:

document.addEventListener("keydown", function (e) {
    var caps = e.getModifierState && e.getModifierState('CapsLock');  // true if pressed, false if released
    document.onkeyup = function(event) {
    if(caps === true){
        /** Validate keys are to be processed */
        var keycode = event.which;
        // works off course only if ctrl key is kept pressed during key stroke = normal behavior in most OS
        // Should it work like a ctrl-Lock function you have to work with a state variable
            if ((event.ctrlKey === true) && (keycode === 18)) {  
                alert();
            }
            else{
                /** Let it happen, don't do anything */
                return;
            }
        }
    };
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM