admin管理员组文章数量:1375246
This code will fire an alert if I hit either Ctrl key:
$('#text').bind('keypress', function(e) {
if(e.keyCode==17)
{
alert("Boo ya");
}
});
Any way to only fire the alert if only the left Ctrl key is pressed?
This code will fire an alert if I hit either Ctrl key:
$('#text').bind('keypress', function(e) {
if(e.keyCode==17)
{
alert("Boo ya");
}
});
Any way to only fire the alert if only the left Ctrl key is pressed?
Share Improve this question edited May 6, 2015 at 13:18 Abhishek 7,04514 gold badges61 silver badges89 bronze badges asked Dec 10, 2010 at 1:37 wkmwkm 1,7627 gold badges24 silver badges40 bronze badges 1- possible duplicate of How can I tell if an event es from right Ctrl key? – Platinum Azure Commented Feb 8, 2013 at 17:22
2 Answers
Reset to default 6I'm aware this question is quite old but nowadays it seems to be possible KeyboardEvent.code:
document.getElementById('i').addEventListener("keyup", function(e) {
e.target.value = e.code;
});
<input id="i" value="try keyboard here">
You should get ShiftLeft
or ShiftRight
by pressing either Shift key.
You can't, at least using the keyCode. It'll be 17 for both keys. I don't know of any other method to distinguish between the two, and in my opinion, it's unlikely that there is one.
本文标签:
版权声明:本文标题:javascript - Can you distinguish between the left CTRL key and right CTRL key using keycodes in .keypress()? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743878975a2554849.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论