我希望有一个事件监听器,控制台在同时按下ctrl +左/右箭头键后记录文本字符串。但是,该事件未被以下功能选中:
public ICollection<int> method()
{
ICollection<int> col = new List<int>();
return col;
}
HashSet<int> result = (HashSet<int>) method();
知道我做错了什么吗?
答案 0 :(得分:1)
if分支存在问题,同时CTRL+Left
按键同时记录ctrl-left
和nothing detected
。
此外,需要停止浏览器的默认事件处理以避免问题。
这对我在Firefox 44.0.2上有用:
$(document).keydown(function (event) {
event.preventDefault();
if (event.which === 37 && event.ctrlKey) {
console.log('ctrl-left');
} else if (event.which === 39 && event.ctrlKey) {
console.log('ctrl-right');
} else {
console.log('nothing detected');
}
});