kegel/web/input.js

113 lines
2.2 KiB
JavaScript

const kbdPressed = {
a: false,
s: false,
d: false,
f: false,
c: false
};
function inputHandle () {
if (kbdPressed.c) {
calibrate = true
sendAll('/ww/calibrate')
}
if (kbdPressed['-']) {
sendAll('/ww/reload')
window.location.reload()
}
if (kbdPressed.d && !cakajDeformiraj) {
deformiraj = !deformiraj
cakajDeformiraj = true
const args = [{
type: "f",
value: deformiraj
}];
sendAll('/ww/zoom', args)
setTimeout(() => cakajDeformiraj = false, 200)
}
if (kbdPressed.g && !cakajZogice) {
zogice = !zogice
cakajZogice = true
const args = [{
type: "i",
value: zogice ? 1 : 0
}];
sendAll('/ww/zogice', args)
setTimeout(() => cakajZogice = false, 200)
}
if (kbdPressed['l'] && !cakajDodatniKegli) {
dodatniKegli = !dodatniKegli
console.log('sprememba kegli', dodatniKegli)
cakajDodatniKegli = true
const args = [{
type: "i",
value: dodatniKegli ? 1 : 0
}];
sendAll('/ww/kegli', args)
setTimeout(() => cakajDodatniKegli = false, 200)
}
}
window.addEventListener('keydown', e => {
kbdPressed[e.key] = true
})
window.addEventListener('keyup', e => {
if (e.key in kbdPressed) {
kbdPressed[e.key] = false
}
})
window.addEventListener('mousedown', e => {
e.preventDefault()
switch (e.button) {
case 0:
kbdPressed['miska'] = true
zacniAnalizo()
break;
case 2:
kbdPressed['miskaD'] = true
}
return false
})
window.addEventListener('mouseup', e => {
if ('miska' in kbdPressed) {
kbdPressed['miska'] = false
}
if ('miskaD' in kbdPressed) {
kbdPressed['miskaD'] = false
}
})
var skrolam = false;
var zadnjiSkrol = 0;
window.addEventListener('mousemove', e => {
if (kbdPressed['miska']) {
/*
const sprememba = (e.movementX + e.movementY) / 10
spremeniZoom(sprememba)
console.log('nov zoom', sprememba)
const args = [{
type: "f",
value: sprememba
}];
sendAll('/ww/zoom', args)
*/
}
/*
if (kbdPressed['miskaD']) {
const sprememba = (e.movementX + e.movementY) / 10
spremeniDeformiraj(sprememba)
const args = [{
type: "f",
value: sprememba
}];
sendAll('/ww/deformiraj', args)
}
*/
})