qaispak qaispak - 1 year ago 93
Javascript Question

using shift with left click for event without Jquerry

My goal is to press a button and perform an action only when the shift key is also pressed. however, it doesn't even seem to recognize the shift key right now. Currently it works with only the right click but like i said, I want it to work with right click + shift.

button.addEventListener("oncontextmenu", function(e) {
document.addEventListener("keydown", function(e) {
console.log("this string wont show");
if (e.keyCode == 16) {
console.log("this string wont show either");
} else {
console.log(e.keyCode); // again it wont show
rightShiftClick(e); // this will execute perfectly.

Answer Source

The event object tells you if the shift key is pressed and there is no "on" when you are attaching the event.

button.addEventListener("contextmenu", function(e) { 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download