arrow keys function javascript
//detecting arrow key presses
document.addEventListener('keydown', function(e) {
switch (e.keyCode) {
case 37:
alert('left');
break;
case 38:
alert('up');
break;
case 39:
alert('right');
break;
case 40:
alert('down');
break;
}
});document.onkeydown = checkKey;
function checkKey(e) {
e = e || window.event;
if (e.keyCode == '38') {
// up arrow
}
else if (e.keyCode == '40') {
// down arrow
}
else if (e.keyCode == '37') {
// left arrow
}
else if (e.keyCode == '39') {
// right arrow
}
}document.addEventListener('keydown', function(e) {
switch (e.keyCode) {
case 37:
alert('left');
break;
case 38:
alert('up');
break;
case 39:
alert('right');
break;
case 40:
alert('down');
break;
}
});
document.onkeydown = checkKey;
function checkKey(e) {
e = e || window.event;
if (e.keyCode == '38') {
// up arrow
}
else if (e.keyCode == '40') {
// down arrow
}
else if (e.keyCode == '37') {
// left arrow
}
else if (e.keyCode == '39') {
// right arrow
}
}
Also in JavaScript:
- how to create react app in vs code
- react generate ethereum address
- javascript insert item into array
- chroma js contrast check
- react native updating options with setoptions
- node close rabbitmq connection
- node send file
- create multidimensional array javascript for loop
- how to get csrf token in javascript
- require a json as a string
- clone an object javascript
- functions in javascript
- dracula theme color scheme windows terminal app
- javascript if has jquery loaded
- how to open html file with javascript
- resellerclub api with react js
- how to add data modal target attribute in jquery
- serverless and connections mongodb atlas
- react native vector icons
- code intialization problem javascript
- toggle jquery remove others
- using d3 to add svg box example
- javascript Inserting values in between an array
- input output ionic