MZ Mouse X,Y and Picture X,Y by pixel

My project is pretty much a 'mouse' only project. Like a point & click adventure game of sorts. The problem I'm having is Rpg Maker basically only has 2 options for mouse inputs. Left Click (inputOk), and Right Click (inputCancel/Menu). Normally in games like this Right Click is supposed to offer you some utility options.

I've currently disabled the right clicks ability to cancel/open the menu. I'm trying to make it open a common event, but it also needs to pass information to that common event. In my case I would like it to pass over the pictureId of the picture the mouse was hovered over at the time of the click.

So the things I'm currently missing are:
1. Finding out the current mouse X&Y. I'm assuming this has my answer:
JavaScript:
TouchInput._onRightButtonDown = function(event) {
    const x = Graphics.pageToCanvasX(event.pageX); //<--- I'm assuming this would give me X position of mouse.
    const y = Graphics.pageToCanvasY(event.pageY); //<--- Likewise this would give me Y position.
    if (Graphics.isInsideCanvas(x, y)) {
        this._onCancel(x, y);
    }
};
If someone could confirm/deny and point me in the right direction I'd be very appreciative.

2. A way to compare the mouse X&Y to determine if a picture is beneath the mouse at the time of clicking. At the moment I'm not too concerned about transparent/alpha pixels. So long as the mouse is within the bounds of the pictures displayed dimensions (meaning it is relevant to the scale currently shown) it should be fine.

I know this is possible since there are a few plugins that have 'on hover' effects for pictures and they detect alpha/transparent pixels. Like VisuStella, or with Caethyril's plugin, but I couldn't quite discern what it was that made them work like that. So some help is needed.
MZ defines Sprite_Picture so that it inherits from Sprite_Clickable, which includes all the basic rectangle hit-test stuff. By default the implemented triggers are press (mouse 1), click, enter, and exit.

I imagine you could patch Sprite_Picture.prototype.processTouch (cf Sprite_Clickable.prototype.processTouch) to add a check for TouchInput.isCancelled() and react accordingly, e.g. (untested):
JavaScript:
/*:
 * @target MZ
 * @plugindesc Cancel trigger for pictures.
 * @help Free to use and/or modify for any project, no credit required.
 */
void (() => {
'use strict';
  const alias_processTouch = Sprite_Picture.prototype.processTouch;
  Sprite_Picture.prototype.processTouch = function() {
    // do usual touch process
    alias_processTouch.apply(this, arguments);
    // also check for cancel
    if (this.isClickEnabled() && this._hovered && TouchInput.isCancelled()) {
      console.log(`Touch cancelled on picture ${this._pictureId}.`);
    }
  };
})();

MZ makes per-pixel tests relatively simple, because the sprite's hitTest method (again, inherited from Sprite_Clickable) receives internal picture coordinates, i.e. you don't have to worry about the picture's current screen position, scale, rotation, or skew. See the getPixel and getAlphaPixel methods of Bitmap (rmmz_core.js) for details~
Some while ago, I worked on a Plugin to enable some more Commands when hovering or clicking on Pictures. Right now, I have no plans to officially release it as there are already some Plugins out there, but maybe you can peek a little bit.

You can do, for example:
JavaScript:
// check if it is hovered right now
const b = $gameScreen.picture(1).isBeingTouched();

// enable a hook
$gameScreen.picture(1).onMouseEnter = () => $gameSwitches.setValue(1, true)
$gameScreen.picture(1).onMouseLeave = () => $gameSwitches.setValue(1, false)
$gameScreen.picture(1).onClick = () => $gameTemp.reserveCommonEvent(1)

There are also some Plugin Commands to switch Switches or call Common Events.
Thank you both, I'll take a look at them and see if I can't mash enough things together to get it work.
Some while ago, I worked on a Plugin to enable some more Commands when hovering or clicking on Pictures. Right now, I have no plans to officially release it as there are already some Plugins out there, but maybe you can peek a little bit.

You can do, for example:
JavaScript:
// check if it is hovered right now
const b = $gameScreen.picture(1).isBeingTouched();

// enable a hook
$gameScreen.picture(1).onMouseEnter = () => $gameSwitches.setValue(1, true)
$gameScreen.picture(1).onMouseLeave = () => $gameSwitches.setValue(1, false)
$gameScreen.picture(1).onClick = () => $gameTemp.reserveCommonEvent(1)

There are also some Plugin Commands to switch Switches or call Common Events.

Hello how are you?, I am interested in this plugin to execute events when you click on an picture but I don't know how it works.

I already imported it to my project but I don't know how to modify the plugin so that it executes a common event when an picture is clicked, help me, please
Hello how are you?, I am interested in this plugin to execute events when you click on an picture but I don't know how it works.

I already imported it to my project but I don't know how to modify the plugin so that it executes a common event when an picture is clicked, help me, please
Thanks for your interest. As already stated, this is a Plugin I made for my project, and I have no plans to release it officially, but it may be some base for other developers to kick off. You probably want to look out for other Plugins that are maintained and updated by their developers for your game.

For RMMV, you probably need to remove this section:
Code:
PluginManager.registerCommand('MK_Pictures', 'bindToSwitch', args => {
    const picture = $gameScreen.picture(Number(args.pictureId));
    if (picture) {
        picture.onClickEnableSwitchId = Number(args.switchId);
    }
});

PluginManager.registerCommand('MK_Pictures', 'bindToSelfSwitch', args => {
    const picture = $gameScreen.picture(Number(args.pictureId));
    if (picture) {
        picture.onClickSelfSwitchEventId = args._eventId;
        picture.onClickSelfSwitchLetter = args.selfSwitch;
        picture.onClickSelfSwitchOperation = 'ON' == args.operation;
    }
})

PluginManager.registerCommand('MK_Pictures', 'bindToCommonEvent', args => {
    const picture = $gameScreen.picture(Number(args.pictureId));
    if (picture) {
        picture.onClickReserveCommonEvent = Number(args.commonEventId);
    }
});

PluginManager.registerCommand('MK_Pictures', 'eraseAllPictures', _ => {
    for (let id = 0; id < 51; id++) {
        $gameScreen.erasePicture(id);
    }
})

Besides that, it may still not work for MV. I don't guarantee that it will work in your game, but when it does, I already described in my earlier post what to do to call a Common Event when clicking on a Picture.

Code:
<> Show Picture: Id: 1
<> Call Script: $gameScreen.picture(1).onClick = () => $gameTemp.reserveCommonEvent(2)

This will start Common Event 2 when clicking on Picture 1.

Original thread: https://forums.rpgmakerweb.com/threads/mouse-x-y-and-picture-x-y-by-pixel.154580/