Board index » delphi » Form OnMouseDown Event - Release mouse key?

Form OnMouseDown Event - Release mouse key?

Hi,

I want to detect when the user presses the mouse key on a certain area
on my form, so I'm using the Form's OnMouseDown event to do this.

However, after I've performed my action once it won't trigger again
until the user releases the mouse key and presses it again.

How do I make my action trigger immediately again if the user still
has the mouse key down? Am I using the wrong event?

Thanks,

Damot

 

Re:Form OnMouseDown Event - Release mouse key?


Quote
Damot Taylor wrote in message ...
>I want to detect when the user presses the mouse key on a certain area
>on my form, so I'm using the Form's OnMouseDown event to do this.

Mouse key? My keyboard has no such key. My mouse has buttons.
And when I press them, OnClick events happen.

Quote
>However, after I've performed my action once it won't trigger again
>until the user releases the mouse key and presses it again.

Correct. A click is one OnMouseDown, one OnMouseUp, and one
OnClick. Assuming that you did everything right so it really
came out as a click, and it might come between the other two.
Or not. You check.

Quote
>How do I make my action trigger immediately again if the user still
>has the mouse key down? Am I using the wrong event?

Set a flag in the OnMouseDown event and clear it in OnMouseUp.
You may want to insert a short delay (USING A TIMER! NOT DELAY!)
before repeating.

Groetjes,
Maarten Wiltink

Re:Form OnMouseDown Event - Release mouse key?


Quote
Damot Taylor wrote:
> Hi,

> I want to detect when the user presses the mouse key on a certain
area
> on my form, so I'm using the Form's OnMouseDown event to do this.

> However, after I've performed my action once it won't trigger again
> until the user releases the mouse key and presses it again.

> How do I make my action trigger immediately again if the user still
> has the mouse key down? Am I using the wrong event?

Probably, what are you trying to do exactly? You might find
onmousemove handy as you can use the x,y coordinates but if you want
to
trigger several things with just the one event then you'll probably
have to use a timer as the trigger.

Re:Form OnMouseDown Event - Release mouse key?


Yes, sorry guys I meant mouse button not key...

All I want to do is detect when the user is holding the mouse button
down over an area on my form and perform an action when he/she is
doing it. Like when you press the arrow icons in a listbox or other
windows control. You don't have to release the button and press it
again.

Doing this in the MouseMove event is no good because the user doesn't
always move the mouse. MouseClick or MouseDown also trigger once and
the user has to release the button and trigger it again.

Regards,

Damot

Re:Form OnMouseDown Event - Release mouse key?


Quote
Damot Taylor wrote:

> Yes, sorry guys I meant mouse button not key...

> All I want to do is detect when the user is holding the mouse button
> down over an area on my form and perform an action when he/she is
> doing it. Like when you press the arrow icons in a listbox or other
> windows control. You don't have to release the button and press it
> again.

> Doing this in the MouseMove event is no good because the user doesn't
> always move the mouse. MouseClick or MouseDown also trigger once and
> the user has to release the button and trigger it again.

> Regards,

> Damot

This may satisfy your requirements:

Save the Sender of the OnMouseDown event as a control in, say, Target.

In the OnMouseUp event, make Target nil to ignore the target control.
You may want to do this also in OnMouseMove.

When the arrow key is detected in OnKeyDown, if Target is not nil, then
find the control under the mouse using the global Mouse variable and
FindDragTarget(Mouse.CursorPos, false).

I think this captures the condition "Mouse button down and on control
Target
and arrow key pressed."  FindDragTarget as described in the help files
seems to work this way, but there's at least one other way to determine
whether the mouse is located on a control.

Regards,
Brian Clausing

Other Threads