MV How to assign a variable to the mouse cursor position?

I'm trying to use scripts in an event to track the position of the mouse cursor in two variables for its x and y coordinates, but I don't know any code so I can't figure it out (I tried looking for plugins that could do this but had no luck).
The idea is that I have an event running parallel tracking the position of the mouse and scrolling the map if the coordinates are near the edges of the screen. If anyone who knows how to code could help with this it would be greatly appreciated!
Moved to: Plugin Requests
In a Variable Operation, you can type a Script. Type this

TouchInput.x and TouchInput.y
It looks like that only works when I click, is there a way for it to work when the cursor is just hovering?
It looks like that only works when I click, is there a way for it to work when the cursor is just hovering?
It does work when the cursor is hovering - whenever you call this script, it will grab the current mouse coordinates. Are you only calling the event when you click?

EDIT: Disregard this, that's only with QIpnut xD
I have the event running parallel and the variables only seem to update when I click the mouse. I can send a screenshot when I get home in a few hours.
By default RMMV does not update touch coordinates on move unless the mouse button is pressed while moving. Presumably an attempt to align mouse and touch-screen interactions. (RMMZ introduces a "hover" mechanic that updates touch coordinates when moved without being pressed.)

You could try loading this as a plugin (untested):
JavaScript:
/*: 
 * @target MV
 * @plugindesc Update touch coordinates regardless of mouse buttons pressed.
 * @help Free to use and/or modify for any project, no credit required.
 */
void (function() {
  var alias = TouchInput._onMouseMove;
  TouchInput._onMouseMove = function(event) {
    alias.apply(this, arguments);
    this._x = Graphics.pageToCanvasX(event.pageX);
    this._y = Graphics.pageToCanvasX(event.pageY);
  };
})();
[Edit: whoops, corrected x to Graphics.pageToCanvasX(event.pageX) and similarly for y. 😴]
By default RMMV does not update touch coordinates on move unless the mouse button is pressed while moving
Huh, I did not expect that, it does update constantly for me (I'm not pressing any mouse buttons in this clip):
Spoiler: A short gif
@Mac15001900 - I can't reproduce that. Are you perhaps using a touch-screen?

You don't appear to be running on the default setup: the "MacThings" message looks like a plugin feature, and it's using PIXI v4.8.9 rather than v4.5.4. The latter probably won't affect this issue directly but it suggests that there may be other edits.

Core script reference (rpg_core.js, "1.6.2"):
JavaScript:
TouchInput._onMouseMove = function(event) {
    if (this._mousePressed) {
        var x = Graphics.pageToCanvasX(event.pageX);
        var y = Graphics.pageToCanvasY(event.pageY);
        this._onMove(x, y);
    }
};
@Mac15001900 - I can't reproduce that. Are you perhaps using a touch-screen?

You don't appear to be running on the default setup: the "MacThings" message looks like a plugin feature, and it's using PIXI v4.8.9 rather than v4.5.4. The latter probably won't affect this issue directly but it suggests that there may be other edits.

Core script reference (rpg_core.js, "1.6.2"):
JavaScript:
TouchInput._onMouseMove = function(event) {
    if (this._mousePressed) {
        var x = Graphics.pageToCanvasX(event.pageX);
        var y = Graphics.pageToCanvasY(event.pageY);
        this._onMove(x, y);
    }
};
Yeah, that's with some plugins - I was just showing how it looked like on my end. I probably should have made that clearer, my bad . Sorry for making you waste time trying to reproduce it.

To elaborate a bit more, I initially posted after a quick test on my project, assuming that since I don't have any plugins that change how mouse/touch input works it will behave the same as in vanilla. Turns out that assumption was wrong, and after some investigating the culprit turned out to be QInput - which is mostly for remapping keyboard keys and doesn't mention that it affects the mouse in its description, but turns out it does xD.

In hindsight I probably should have just set up an empty project and tested it there...
Turns out that assumption was wrong, and after some investigating the culprit turned out to be QInput
Good to know! I only spent a minute or so double-checking the behaviour in a new project, no worries~ 👋
You could try loading this as a plugin (untested):
JavaScript:
/*:
 * @target MV
 * @plugindesc Update touch coordinates regardless of mouse buttons pressed.
 * @help Free to use and/or modify for any project, no credit required.
 */
void (function() {
  var alias = TouchInput._onMouseMove;
  TouchInput._onMouseMove = function(event) {
    alias.apply(this, arguments);
    this._x = x;
    this._y = y;
  };
})();

I tried this and it gave an error message on startup saying "Uncaught ReferenceError: x is not defined" BUT using this context and a bit of searching online I managed to get it working (replacing the x and y in lines 10 and 11 with event.clientX and event.clientY). Assuming no issues crop up from this later on I should be good. Appreciate the help!
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/how-to-assign-a-variable-to-the-mouse-cursor-position.154605/