gpt4 book ai didi

jquery - 尝试绑定(bind) alt gr 键,但在 chrome 中不起作用

转载 作者:行者123 更新时间:2023-12-01 05:14:40 24 4
gpt4 key购买 nike

以前在所有浏览器中都运行良好,但由于某种原因 ALT GR 在 Chrome 中不起作用。我完全没有想法让它发挥作用..

它适用于所有浏览器中的 CTRL + ALT + Q

使用 Chrome 版本 67.0.3396.87(Officiell 版本)(64 位)

$(document).on("keydown", function(event)
{
console.log(event.ctrlKey);
console.log(event.altKey);

// AltGr+Q
if(event.which === 81 && event.ctrlKey && event.altKey)
{
$("#notes").empty('');
$("#notes").append("Success!<br/>" , " Event: ", event.which, " ctrlKey: ", event.ctrlKey, " Altkey: ", event.altKey);
return false;
}
else
{
$("#notes").empty('');
$("#notes").append("Fail! <br/>" , " Event: ", event.which, " ctrlKey: ", event.ctrlKey, " Altkey: ", event.altKey);
return false;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<span id="notes">Klick to focus snippet and test keydown event, works well in Explorer/Edge but not in chrome</span>
<div/>

最佳答案

我找到了问题的答案。我真的不喜欢这个解决方案,因为它有点困惑,而且我不知道它是否防弹。对此的任何见解都将不胜感激,如果这里采取一种外部方法,那会更干净一点。

var altgr = false;   

$(document).on("keyup", function (event) {
if((event.key === "AltGraph"|| event.key ==="Alt")||(event.ctrlKey && event.altKey)){
altgr=false;
}
});

$(document).on("keydown", function(event)
{
var altkey = event.key;
if((event.key === "AltGraph")||(event.ctrlKey && event.altKey)){
altgr = true;
}
console.log(altgr);

// AltGr+Q
if(event.which === 81 && altgr)
{
$("#notes").empty('');
$("#notes").append("Success!<br/>" , " Event: ", event.which, " ctrlKey: ", event.ctrlKey, " Altkey: ", event.altKey);
return false;
}
if(event.which === 87 && altgr)
{
$("#notes").empty('');
$("#notes").append("Success!<br/>" , " Event: ", event.which, " ctrlKey: ", event.ctrlKey, " Altkey: ", event.altKey);
return false;
}
else
{
$("#notes").empty('');
$("#notes").append("Fail! <br/>" , " Event: ", event.which, " ctrlKey: ", event.ctrlKey, " Altkey: ", event.altKey);
return false;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<span id="notes">Click to focus snippet and test keydown event, works well in Explorer/Edge but not in chrome</span>
<div/>

关于jquery - 尝试绑定(bind) alt gr 键,但在 chrome 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50834466/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com