The Official Blog of Patcoola

Im just a dude watching over my parents,
and trying to make cartoons and video games from home.

Script: Mouse Buttons [JS]

Important!

Dear visitors,

This blog and the Tigarus.com network will be changing our website software in May (2024). There will be some down time and there will be a change to the webpage addresses.

We will also be removing the Anime blogs. The Rocksmith Songs website will be unavailable of a few weeks or months while I move the database to the new software.

At the moment we are running on Wordpress, the new software is an in-house project which is 57 times faster. It will also provide more freedom for development.

Thank you for understanding.

, By Patcoola

Script Title: mouseButtons
Programming Language: Java Script
Date Completed: 2012/09/16

Purpose: To detect if a mouse button is pressed. Returns true or false.

Advertisement

Donate Now!

After a hard day, I like to relax with a cold jar of pickle juice and a hardy fart. If you like my blog, please consider donating.


Description: An easy to use system for handling Mouse buttons with Java Script.

Compatibility: Works with all modern Web browsers, with limited legacy support.

Caution: Opera browsers older than version 12 have the ability to detect the context menu action disabled by default. This means the mouse button assigned as “Right Click” will not be detectable, unless this feature is enabled by the user.

AppleWebKits based Web browsers (Safari/Chrome), version 412 and earlier only detect Left Clicks.

Method:

Functions
mouseButton.isDown( String );Determines if a button is down, returns true or false
mouseButton.isUp( String );Determines if a button is up, returns true or false
mouseButton.start();Starts mouse button listeners
mouseButton.stop();Stops mouse button listeners

Variables
mouseButton.isActive;Returns true or false if the listeners are active
mouseButton.disableContextMenu;Set or Returns true if menu is disabled
mouseButton.disableCtrlClick;Set or Returns true if Ctrl is disabled
mouseButton.disableShiftClick;Set or Returns true if Shift is disabled
mouseButton.disableAltClick;Set or Returns true if Alt is disabled
mouseButton.disableCmdClick;Set or Returns true if CMD is disabled

isDown and isUp Arguments:

left
middle
right
ctrl
shift
alt
cmd

Note: Arguments are not case sensitize.

Notice: Mouse buttons are defined as actions in the computer’s system properties. Many people may not be able to detect their middle button because this button maybe assigned a different action. For example you could assign the button, the Flip action, now the button is called Flip. If you assign the Left button as Left Click, the button will be detected as Left, if you assign the Left button as Right Click the Left button is now detected as Right.

Disable Context Menu:

Default value is false, when set to true the context menu (default right click action) is disabled.
Note: Some users or Web browsers may have the ability to detect this event disabled.

Disable Control Click:

Default value is false, when set to true the Ctrl+Click action of the Web browser is disabled.
Note: Ctrl+Click to open a link in a new tab is still active, to disable this action will require the link’s behavior to be change.

Disable Shift Click:

Default value is false, when set to true the Shift+Click action of the Web browser is disabled.

Disable Alt Click:

Default value is false, when set to true the Alt+Click action of the Web browser is disabled.

Disable Command Click:

(Mac)
Default value is false, when set to true the CMD+Click action of the Web browser is disabled. This feature is for Apple computers.

Example Usage:

// left mouse button

mouseButton.start();

function onMouseEventDown() {
if ( mousedown.isDown( “Left” ) ) {
// do something
}
}
document.addEventListener(‘mousedown’, onMouseEventDown, false);

 

Advertisement

Donate Now!

Hey buddy, it takes a lot to make a blog. How about a donation?


 

Post Meta

Share Post

 

Comments: Write Comment

Be the first to write a comment.


Leave a Comment


All comments are reviewed before publishing. Comments must be related to the page topic, must not be spam, and must comply with the criminal code of Canada.

 
20.36207 milliseconds