473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Get mousebuttonstate in NS

Hello,

In an event handler for onmousemove I want to know if a mousebutton is
currently prtessed. In IE "event.button == 1" works fine for me. In NS I
always get event.button == 0 in onmousemove event if the mousebutton is
pressed.

How do I get the mousebutton state?

TIA

Silvio Bierman
Jul 20 '05 #1
4 1330
Silvio Bierman wrote:
In an event handler for onmousemove I want to know if a mousebutton is
currently prtessed. In IE "event.button == 1" works fine for me. In
NS I always get event.button == 0 in onmousemove event if the
mousebutton is pressed.

How do I get the mousebutton state?


By adding a listener for the mousedown event:
document.addEventListener("mousedown", showButtonFunction, false);
JW

Jul 20 '05 #2
DU
Silvio Bierman wrote:
Hello,

In an event handler for onmousemove I want to know if a mousebutton is
currently prtessed. In IE "event.button == 1" works fine for me. In NS I
always get event.button == 0 in onmousemove event if the mousebutton is
pressed.

How do I get the mousebutton state?

TIA

Silvio Bierman

You must query the button property of the created event object once
you've created an event listener in Mozilla-based browsers.
"0" is the left button, "1" is the middle button and "2" is the right
button.

E.g.:

function init()
{
document.addEventListener("mousedown", showButtonFunction, false);
}

function showButtonFunction(evt)
{
document.getElementById("idParg").style.visibility = "visible";
var txtMouseButton = evt.button == "0" ? "left" : evt.button == "1" ?
"middle" : "right";
document.getElementById("idMouseButton").firstChil d.nodeValue =
txtMouseButton;
}
// this code could be further improved and made more robust
</script>

</head>

<body onload="init();">

<p id="idParg" style="visibility:hidden;">You just have clicked the
button of your <span id="idMouseButton">&nbsp;</span> mouse.</p>

Tested and working without a problem in Mozilla 1.6 beta, NS 7.1 and
K-meleon 0.8.2.

DU
Jul 20 '05 #3
OK guys,

That is what I thought. I have solved it that way but thought there might be
a more elegant way of querying the button states during any other event. I
now use a document level event that sets/clear global button-down flags for
use in other event handlers, not nice but it works.

Thanks,

Silvio Bierman
Jul 20 '05 #4
Silvio Bierman wrote:
In an event handler for onmousemove I want to know if a mousebutton is
currently prtessed. In IE "event.button == 1" works fine for me. In NS I
always get event.button == 0 in onmousemove event if the mousebutton is
pressed. How do I get the mousebutton state?


Use the "which" property instead and be sure to pass and use
a reference to the local event object ("event" in an intrinsic
HTML event handler attribute) in the case the IE-proprietary
global "event" object is undefined.
PointedEars
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Jarod_24 | last post by:
I got a project called "Forms" that hold some forms and stuff in my solution. A argument at startup defines wether to use a From or Console. My plan was to create a myConsole class that would...
13
by: Mark A. Nadig | last post by:
I've got a console application in vb.net to replicate the behavior of the old DOS command CHOICE. I've got a timer event successfully firing, however the main thread is stuck on the console.read()....
8
by: Eps | last post by:
Hi there, Is there a way to get the progressbar value when a user clicks on it ? I am using wpf at the moment but windows forms solutions would be welcome too. I get the the x and y...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.