473,387 Members | 1,512 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,387 software developers and data experts.

Loop while mousedown?????

I am quite familiar with JavaScript and many other programming
languages as I am a programmer for a living. However, I am having a
heck of a time figuring out this problem. I would like to have a
function loop as long as the mouse button is pressed. I am aware of the
onMouseDown event to fire the loop, but I cann't figure out how to stop
the loop with the onMouseUp event.

I have tried setting a boolean value with the onMouseDown event, but
once I release the mouse button, the boolean value cannot be changed
until the loop is done. So, as the loop is waiting for the value to be
changed, it becomes an infinite loop. Many people have offered
suggestions, but none of them seem to work.

Is there such a method as whileMouseDown, or is it possible to cancel a
function with onMouseUp?

This must be possible.... I am basically trying to scroll through an
image hidden behind a division, much like scrolling through a web page.
When you hold down the arrow key, it scrolls until you let go...

I would greatly appreciate any help anyone can offer. I am using IE 6.0
and I will include a code sample of what I have been doing:

var ismousedown=0;

document.onmousedown = mouseDown;
document.onmouseup = mouseUp;

function mouseDown()
{
ismousedown = 1;
}
function mouseUp()
{
ismousedown = 0;
}
function getMouseValue()
{
return ismousedown;
}
function checkMouse()
{
if(getMouseValue == 0)
{

}else
{
moveDown();
setTimeout("checkMouse()",500);
}
}

Jul 23 '05 #1
3 11834
Lee
pl****@mbl.edu said:

I am quite familiar with JavaScript and many other programming
languages as I am a programmer for a living. However, I am having a
heck of a time figuring out this problem. I would like to have a
function loop as long as the mouse button is pressed. I am aware of the
onMouseDown event to fire the loop, but I cann't figure out how to stop
the loop with the onMouseUp event.


Use setInterval() to start the loop onMouseDown and clearInterval() to stop it
onMouseUp.

Jul 23 '05 #2

<pl****@mbl.edu> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
<SNIP>
if(getMouseValue == 0)


I'm not saying this will fix things, but if the above statement is an
accurate transcript of your working code, I'm sure you'll see the problem.

--
S.C.

Jul 23 '05 #3
pl****@mbl.edu wrote:
I am quite familiar with JavaScript and many other programming
languages as I am a programmer for a living. However, I am having a
heck of a time figuring out this problem. I would like to have a
function loop as long as the mouse button is pressed. I am aware of the
onMouseDown event to fire the loop, but I cann't figure out how to stop
the loop with the onMouseUp event.


Have a read here, particularly the bit about event handlers.

<URL:http://www.quirksmode.org/js/introevents.html>

I think you want to fire the scroll onmousedown, then cancel it with
onmouseup and maybe onmouseout also.

Hope it helps :-)

--
Rob
Jul 23 '05 #4

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

Similar topics

2
by: JJ | last post by:
Hi All, I need to create a MouseDown event for a picture box . Am I doing the following right? pictureBox.MouseDown += new System.WinForms.MouseEventHandler(pictureBox_MouseDown) Then
1
by: Jürgen Müllder | last post by:
Hi! I have a TreeView in my Application. I have the MouseDown Attached to the TreeView. When i click at a Node it makes that what it should. But when i Expand a Node by clicking at the Plus Sign...
7
by: Scott Mackay | last post by:
Hi, I'm using visual studio dotnet 2002 programming in vb can anyone tell me how I can handle the mousedown event for pictureboxes I create dynamically at runtime? I've tried setting the...
4
by: rsmith | last post by:
How can I capture the MouseDown event on a Label ? I entered thr following code and got a " cannot handle Event 'MouseDown' because they do not have the same signature." Private Sub...
2
by: Rob | last post by:
How can I fix the following warning warning BC40004: sub 'MouseDown' conflicts with event 'MouseDown' in the base class 'Control' and so should be declared 'Shadows'. This warning appears...
1
by: Alan | last post by:
i have a form with a label on it Private Sub Label1_mousedown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown ' do stuff End Sub ...
1
by: JDeats | last post by:
It appears the WinForm MouseDown and MouseUp event handlers are not working properly. In the "bare bones" sample application below, Form1_MouseUp gets called even through the mouse button remains...
2
by: lmefford | last post by:
Is there a way to modify all textboxes on a form so that when you click on any of them you process the SelectAll() function. For exaple, let's say I've created a form with 30 textboxes. These...
2
by: FPyro | last post by:
Hey, I try to delay a loop, but the "animatedgif" don't move at all, when I place another loop inside the loop. Thanks for the help Private Sub PictureBox2_MouseDown(ByVal sender As...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.