Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to add keyboard shortcuts javascript

document.addEventListener("keydown", (event) => {
	/*
		event.key returns the character being pressed
        event.preventDefault() prevents the default browser behavior for that shortcut, e.g. ctrl+r usually reloads the page, but event.preventDefault() will turn off that behavior. event.preventDefault() should only be used if you share a shortcut with the same trigger as the browser.
        event.ctrlKey / event.altKey / event.shiftKey / event.metaKey all return booleans. They will be true when they are being pressed, otherwise they will be false.
	*/
	if (event.ctrlKey && event.key.toLowerCase() === "d") {
    	//Do something
	} else if (event.ctrlKey && event.key.toLowerCase() === "p") {
    	//Do something else
	}
});	
Comment

Javascript keyboard shortcuts

document.onkeyup = function(e) {
    if (e.which == 16) {
        alert('You have press Shift')
    }
    if (e.which == 17 && e.which == 13) {
        alert('You have press CTRL + Enter')
    }
    //Keyboard events codes
    //https://www.toptal.com/developers/keycode
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: stringbuffer javascript 
Javascript :: parse query url javascript 
Javascript :: Filtering an array for unique values 
Javascript :: react sass 
Javascript :: take off element form end of array 
Javascript :: javascript post 
Javascript :: mongoose getters 
Javascript :: javascript output a message into console 
Javascript :: javascript remove the last element from array 
Javascript :: how to remove an item from an object in javascript 
Javascript :: Auto increment in realtime database with javascript 
Javascript :: angular architecture patterns 
Javascript :: js code 
Javascript :: javascript pass array by value 
Javascript :: console.group in javascript 
Javascript :: determine location of ip address nodejs 
Javascript :: parse json java 
Javascript :: default javascript 
Javascript :: react-native-geolocation-service 
Javascript :: double click react 
Javascript :: where to create service angularor nodejs 
Javascript :: in express how do you set the location header 
Javascript :: react code input 
Javascript :: delete div based on select 
Javascript :: how to refrence schema in my mongoose schema 
Javascript :: javascript class in external file 
Javascript :: uploading json data to s3 bucket in node js 
Javascript :: var s= 
Javascript :: react native textinput disable keyboard 
Python :: jupyter display all columns 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =