Extend javascript key pressed function

I’ve a such a small javascript on my website, to control the site by pressing the arrow keys on my keyboard.

document.onkeydown = function(evt) {
    evt = evt || window.event;
    switch (evt.keyCode) {
        case 37:
            leftArrowPressed();
            break;
        case 39:
            rightArrowPressed();
            break;
    }
};

function rightArrowPressed() {
     window.open("next-page.php","_self")
}
function leftArrowPressed() {
     window.open("pre-page.php","_self")
}

If I’m pressing the right-arrow-key the javascript redirects me to the “next-page.php”. If I’m pressing the left-arrow-key the javascript redirects me to the “pre-page.php”.

I want to extend the script with pressing the + and – key or the q and w key.
The current script should not change ideally.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s