I have a script that toggles the value of a variable when a key is pressed and the key is lifted. I'm wondering how I can change this so that instead of changing a variable value when a key is pressed, the saturation on the screen will change and when the key is lifted, the saturation will revert to its original value. How can this be done? The script:
let x = 1;
window.onkeydown = () => {
let x = 2;
};
window.onkeyup = () => {
let x = 1;
}
css to change the screen saturation: filter: saturate(4);
Just to clarify, when the keydown function occurs instead of changing the variable x from 1 to 2, the screen saturation should change to filter: saturate(4); and when the key is lifted, the screen saturation should revert to normal.
You can do almost anything you want in those functions:
window.onkeydown = () => document.body.style.filter = "saturate(4)";
window.onkeyup = () => document.body.style.filter = "";