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

how to add shortcuts in javascript

document.addEventListener('keydown', (e) => {
    e.preventDefault();

    if (e.key.toLowerCase() === 's' && e.ctrlKey) {
        // Add your code here
        alert('S key pressed with ctrl');
    }
});
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 :: react native activityindicator 
Javascript :: how to make a purge command discord.js 
Javascript :: get scroll position jquery 
Javascript :: nuxt 18 mountend route push 
Javascript :: conditinally object property js 
Javascript :: react native textinput lowercase 
Javascript :: javascript determine array type 
Javascript :: javascript trim each element in array 
Javascript :: yarn react select 
Javascript :: javascript json download 
Javascript :: chrome max local storage size 
Javascript :: javascript hasownproperty 
Javascript :: puppeteer how to type in input 
Javascript :: string to JSONobject + android 
Javascript :: get columns of array list json js 
Javascript :: localstorage read all key 
Javascript :: datatable processing 
Javascript :: jquery translate 
Javascript :: read data from json using node 
Javascript :: go to previous page 
Javascript :: javascript replace <br with n 
Javascript :: javascript modify url without reload 
Javascript :: alphabet letters in js code 
Javascript :: add 1 year to current date javascript 
Javascript :: visual studio appsettings development json not nested appsettings.json 
Javascript :: jquery hover function 
Javascript :: mysql json get value 
Javascript :: jquery radio button change 
Javascript :: check solidity version in current project folder truffle 
Javascript :: clean up async requests in react useEffect hook using abort controller 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =