document.onkeydown = checkKey;

function checkKey(e) {

    e = e || window.event;

    if(e.key == 'a'  || e.key == 'A')
    {
        console.log("back to A position");
        socketDriver.send(`G90 G1 X0 Y300 Z0 A${Math.PI/2} B-${Math.PI/2} C0 F100`);
    }

    // Hand-Winkel (Eulerwinkel)
    else if(e.key == 'i' || e.key == 'I'){
        socketDriver.send('G91 G1 B+0.1 F100');
    }
    else if(e.key == 'k' || e.key == 'K'){
        socketDriver.send('G91 G1 B-0.1 F100');
    }
    else if(e.key == 'l' || e.key == 'L'){
        socketDriver.send('G91 G1 A+0.1 F100');
    }
    else if(e.key == 'j' || e.key == 'J'){
        socketDriver.send('G91 G1 A-0.1 F100');
    }
    else if(e.key == 'o' || e.key == 'O'){
        socketDriver.send('G91 G1 C+0.1 F100');
    }
    else if(e.key == 'u' || e.key == 'U'){
        socketDriver.send('G91 G1 C-0.1 F100');
    }

    // XYZ Koordinaten
    else if(e.key == 'e' || e.key == 'E'){
        socketDriver.send('G91 G1 Z+5 F100');
    }
    else if(e.key == 'd' || e.key == 'D'){
        socketDriver.send('G91 G1 Z-5 F100');
    }
    else if(e.key == 's' || e.key == 'S'){
        socketDriver.send('G91 G1 X5 F100');
    }
    else if(e.key == 'f' || e.key == 'S'){
        socketDriver.send('G91 G1 X-5 F100');
    }
    else if(e.key == 'r' || e.key == 'R'){
        socketDriver.send('G91 G1 Y5 F100');
    }
    else if(e.key == 'w' || e.key == 'W'){
        socketDriver.send('G91 G1 Y-5 F100');
    }

    // File & Log-Operations
    else if(e.key == ' '){
        console.log('FPoint!')
        socketDriver.send('FPoint');
    }
    else if(e.key == 'b'){
        socketDriver.send('FMinus');
    }
    else if(e.key == 'n'){
        socketDriver.send('FPlus');
    }  
}