Hide mouse cursor when idle

Nolonar

Veteran
Veteran
Joined
Feb 18, 2018
Messages
160
Reaction score
232
First Language
French, German
Primarily Uses
RMMZ
EDIT

This plugin is now available on GitHub: https://github.com/Nolonar/RM_Plugins-HideIdleMouse

---

Hello everyone. Today I'd like to release a plugin I just made. (I hope I'm doing this right)
I call it: IdleMouse

It simply hides the mouse cursor when idle.
It also hides the mouse cursor immediately when the game starts, because otherwise the player would need to move the mouse at least once before the auto-hiding kicks in.

Note: The mouse cursor is only hidden when it is inside the game window. This is not a bug.

How to use
Just enable the plugin, that's it.
You can customize how long the mouse can remain idle before it is hidden. By default, the timeout is 3000 milliseconds (3 seconds).


Code:
//=============================================================================
// IdleMouse
//=============================================================================
/*:
* @plugindesc Automatically hides mouse if it hasn't been moved for a while.
* @author Nolonar
*
* @param Idle timeout
* @desc How long the mouse can remain idle before it is hidden (in milliseconds).
* @default 3000
* @type number
*
*
* @help This plugin does not provide plugin commands.
*
* Note:
* The mouse cursor will only be hidden if it is above the game window.
*/
(function() {
    var timeoutDelay = Number(PluginManager.parameters('IdleMouse')['Idle timeout']) || 3000;
    var mouseIdleTimeout = null;
    var defaultCursor = document.body.style.cursor;
    hideMouse(); // Hidden by default.
    var window_onmousemove = window.onmousemove;
    window.onmousemove = function() {
        if (window_onmousemove) window_onmousemove.call(this); // Just in case the event is not yet set.
        showMouse();
        clearTimeout(mouseIdleTimeout);
        mouseIdleTimeout = setTimeout(function() {
            hideMouse();
        }, timeoutDelay);
    };
    function showMouse() {
        document.body.style.cursor = defaultCursor;
    };
    function hideMouse() {
        document.body.style.cursor = 'none';
    };
})();


If you don't care about the mouse at all and simply wish to keep it hidden at all times, you can just use the following one-liner.
Code:
document.body.style.cursor = 'none';


Terms of use
The one-liner (above) has absolutely no Terms of Use. Do with it whatever you want.

The following Terms of Use only apply to the full plugin.

  • Free for use in any RPG Maker game, commercial or not.
  • Credits not required.
  • Modifications allowed.
  • Redistribution allowed, but only if free.
  • Not allowed: Selling the plugin. It may only be sold as part of an RPG Maker game.
  • Not allowed: Claiming ownership of the plugin. You're allowed to claim ownership of any modifications you've made, as long as it's clear that it's a modification and that the original plugin isn't yours.
  • Not allowed: Change the Terms of Use. An exception is made for modifications. You are allowed to set your own Terms of Use for your modification, but it may not conflict against the "claiming ownership" or "selling" Terms.
  • I am not liable for any damage or misfortune incurred before, while, or after using the plugin or any of its modifications.

So basically, my Terms of Use are designed to be as pain-free as possible.
As long as you don't try to steal it or make profits from it (except if you're selling a game that uses the plugin), you're allowed to do pretty much whatever you want, without any obligations. You're not even required to bother with proper crediting.
In return, you agree that you won't use my plugin as an excuse to try to blame me for any misfortune that may have befallen you, past, present, or future.

Just be a decent human being, and we'll all be happy (I hope).
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

--Turn Based Battles--

Hero:
Look, it is Minotaur!
M. Knight: Let's go attack it!
Hero: Wait, no, it is just standing there!!
HUD Display: It is M. Knight's turn.
(M. Knight attacks Minotaur)
HUD Display: It is Minotaur's turn.
Hero: (Facepalms) Now look what you did! You made the Minotaur attack us!
Randomly deciding to create some tombs/sarcophagi last minute is probably not the best choice in a timed game jam...
There are only a few days left in our Spooktober Spooktacular Game Jam! Hope you are working hard to get your game in!
Where do i have to play Heisei Pistol Show the same creator that made Re: Kinder Parun
I really get the feeling I should be doing regular YouTube videos whenever I make something cool in my game, instead of waiting for massive changes. But not going to lie... I always feel like it's never quite enough to merit an update, until it's a drastic change. :kaoswt:

Forum statistics

Threads
104,558
Messages
1,007,127
Members
136,040
Latest member
Nicoh
Top