Skip to content

How to prevent menu popup on right click? #1813

Answered by eonarheim
dpayne5 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @dpayne5,

You can override the browser handler document.oncontextmenu and return false out of it to prevent the default browser behavior

https://codesandbox.io/s/context-menu-9rgk0?file=/src/index.ts

Quick example:

import { Actor, Color, Engine } from "excalibur";

class Game extends Engine {
  initialize() {
    const actor = new Actor({
      x: 100,
      y: 100,
      width: 50,
      height: 50,
      color: Color.Red
    });
    this.input.pointers.primary.on("move", (ev) => {
      actor.pos = ev.worldPos;
    });

    this.input.pointers.primary.on("down", (ev) => {
      console.log(ev.button);
    });

    this.add(actor);

    this.start();
  }
}

document.oncontextmenu = ()…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dpayne5
Comment options

Answer selected by dpayne5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants