Hello
I need to create a shortcut where when I press the SHIFT + mouse LEFT button, it displays an alert. How can I do this very simple and using Jquery?
Thank you
Hello
I need to create a shortcut where when I press the SHIFT + mouse LEFT button, it displays an alert. How can I do this very simple and using Jquery?
Thank you
Use event.shiftKey for this:
With jQuery
$(document).click(function(event) {
if (event.shiftKey) { // tecla shift
console.log("shift+click")
}
if (event.ctrlKey) { // tecla Ctrl
console.log("ctrl+click")
}
if (event.metaKey) { // tecla Meta (CMD nos teclados Apple ou Windows nos outros)
console.log("meta+click")
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
NojQuery:
function logChar(e) {
e.preventDefault();
if(e.shiftKey) {
console.log('shift+click');
}
else if(e.ctrlKey) {
console.log('ctrl+click');
}
else if(e.metaKey) {
console.log('meta+click');
} else {
console.log('click simples');
}
}
<a href='#' onclick="logChar(event);">clique aqui</a>