Detect SHIFT key and click the right mouse button

0

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

    
asked by anonymous 01.11.2016 / 00:09

1 answer

1

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>
    
01.11.2016 / 01:13