keys = [];
longPressTime = 1000;
mouseLpressd = false;
mouseRpressd = false;
mouseMpressd = false;
mouseLLongpressd = false;
mouseRLongpressd = false;
mouseMLongpressd = false;
function isKeyPressed(kc){
if(typeof(kc) == "undefined"){
return false
}
return keys[kc] > 0
}
function isKeyLongPressed(kc){
if(typeof(kc) == "undefined"){
return false
}
return keys[kc] > longPressTime
}
mouseLLongpressdT = 0;
mouseRLongpressdT = 0;
mouseMLongpressdT = 0;
if(typeof(handleWkd) === "undefined"){
handleWkd = true
window.addEventListener("keydown",function(ev) {
keys[ev.keyCode] = 1;
});
window.addEventListener("keyup",function(ev) {
keys[ev.keyCode] = undefined;
});
window.addEventListener("mousedown",function(ev) {
if(ev.button === 0){
mouseLpressd = true;
mouseLLongpressd = false;
mouseLLongpressdT = 0;
}
if(ev.button === 2){
mouseRpressd = true;
mouseRLongpressd = false;
mouseRLongpressdT = 0;
}
if(ev.button === 1){
mouseMpressd = true;
mouseMLongpressd = false;
mouseMLongpressdT = 0;
}
});
window.addEventListener("mouseup",function(ev) {
if(ev.button === 0){
mouseLpressd = false;
mouseLLongpressd = false;
mouseLLongpressdT = 0;
}
if(ev.button === 2){
mouseRpressd = false;
mouseRLongpressd = false;
mouseRLongpressdT = 0;
}
if(ev.button === 1){
mouseMpressd = false;
mouseMLongpressd = false;
mouseMLongpressdT = 0;
}
});
}
if(typeof(handleWkdInv) !== "undefined"){
clearInterval(handleWkdInv)
}
handleWkdInv = setInterval(function(){
keys.forEach(function(v,i){
if(v){
keys[i]+=longPressTime/3;
}
});
if(mouseLpressd){mouseLLongpressdT+=longPressTime/3;mouseLLongpressd = (mouseLLongpressdT >= longPressTime) ? true : false;}
if(mouseRpressd){mouseRLongpressdT+=longPressTime/3;mouseRLongpressd = (mouseRLongpressdT >= longPressTime) ? true : false;}
if(mouseMpressd){mouseMLongpressdT+=longPressTime/3;mouseMLongpressd = (mouseMLongpressdT >= longPressTime) ? true : false;}
},longPressTime/3);