简体   繁体   English

按键javascript ctrl键

[英]Key press javascript ctrl key

Can someone please tell me what's going on with Ctrl key? 有人可以告诉我Ctrl键怎么回事吗? I've tried like every answer of questions about this matter - none work! 我已经尝试过像此问题的所有答案一样,没有任何作用!

$("body").on("keypress", function(e) {
    if (e.which == 49)
        summon = "SpearMan";
    if (e.which == 50)
        summon = "SwordMan";
    if (e.which == e.ctrlKey) {
        console.log("ctrl");
    }
});

Even in w3schools the example they have doesn't work. 即使在w3schools中,他们拥有的示例也不起作用。 Please help. 请帮忙。

So I decided to use this plugin and it didn't work for me because it only helps if I have an https://jqueryui.com/selectable/#display-grid . 因此,我决定使用此插件,它对我不起作用,因为只有在拥有https://jqueryui.com/selectable/#display-grid时,该插件才有用。 So what I did was to find how it used the ctrl key: 所以我要做的就是找到它如何使用ctrl键:

$("body").on("keypress", function(e){
        if(!event.metaKey && !event.ctrlKey) {
            console.log("ctrl");
            gather = true;
        }
});

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

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