Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Shift + Right click in firefox with Javascript

I am working on an RTS game where you can select units and right click to make them go somewhere. You can also shift right click to queue up a list of points you would like the units to travel to.

In all browsers except FF this is working perfectly.

In Firefox however the shift right click triggers a context menu (right click without shift does not). I am handling the contextmenu event and calling preventDefault but that doesn't seem to do anything in FF when the shift button is held.

Is there any way to block this behavior in FF?

My game is here: https://mod.it/4plhXo3l and the code in question in in the RTSBoard.js file on line 36.

like image 250
asutherland Avatar asked Oct 22 '22 14:10

asutherland


1 Answers

I managed to get this working in Firefox by setting event.shiftKey to false, then calling preventDefault(), and stopPropagation(), then returning false. I then set the document model's onclick event and ondblclick events to the same function you wound up using for yourself, plus the added setting of the shiftkey to false. I also had to do this for mouseup events, because clicking and dragging was also causing context menus to pop up.

I'm not sure it can be fully 100% disabled, but this looks to be about the closest you can get it.

like image 74
Nexim Avatar answered Oct 30 '22 18:10

Nexim