Need Help with a Mouse Side-Button Detection Script

0 favourites
  • 1 posts
From the Asset Store
Detects any kind of ad blocker. Very easy implementation into already existing projects
  • Hey, a while ago I made *ahem stole* this script that detects a mouse button press even if it is a side button like FWD/BWD:

    // Import any other script files here, e.g.:
    // import * as myModule from "./mymodule.js";
    
    let r;
    
    runOnStartup(async runtime =>
    {
    	// Code to run on the loading screen.
    	// Note layouts, objects etc. are not yet available.
    	
    	runtime.addEventListener("beforeprojectstart", () => OnBeforeProjectStart(runtime));
    	r=runtime;
    });
    
    async function OnBeforeProjectStart(runtime)
    {
    	// Code to run just before 'On start of layout' on
    	// the first layout. Loading has finished and initial
    	// instances are created and available to use here.
    	document.addEventListener("mousedown", (e) => {e.preventDefault(); mousedown(e.clientX, e.clientY, e.button)});
    	
    	
    	runtime.addEventListener("tick", () => Tick(runtime));
    }
    
    function mousedown(x, y, button){
    	console.log(button);
    	r.globalVars.mouseButtonNum = button;
    }
    
    function Tick(runtime)
    {
    	
    }
    

    Here is the very short events/vars nessesary:

    There are 2 major issues with this system that I need to fix:

    1. It only works if you press a diffrent mouse button before the one you are pressing (e.x. pressing RMB then LMB works, but if you press LMB twice it doesn't work the second consecutive time)

    2. There is no way to check if you are holding the button.

    If anybody knows how I can alter the code/events to fix those issues, please let me know.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)