Board index » cppbuilder » checking if a button is down

checking if a button is down


2008-04-17 01:18:12 AM
cppbuilder30
Hi,
I want to implement the following, when a button is clicked I want to execute an action one time.
If the button is kept held down, I want the action to be executed continuously, until the button is released.
I was thinking having a timer, kicked off by clicking the button. Inside the timers ONTimer, I could check if the button is still pressed, if so I will execute the action, if not,
I will disable the timer.
But how can I check if the Button is in a down state? I've been searching for it but can't find an answer...
-totte
 
 

Re:checking if a button is down

"Totte Karlsson" < XXXX@XXXXX.COM >wrote in message
Quote
I want to implement the following, when a button is clicked I
want to execute an action one time. If the button is kept held
down, I want the action to be executed continuously, until the
button is released.
In the button's OnMouseDown event, start a timer. In its OnMouseUp event,
stop the timer. Do your normal action in the OnClick event, and have the
timer's OnTimer event call the OnClick handler. For example:
void __fastcall TForm1::Button1MouseDown(TObject *Sender);
{
Timer1->Enabled = true;
}
void __fastcall TForm1::Button1MouseUp(TObject *Sender);
{
Timer1->Enabled = false;
}
void __fastcall TForm1::Button1Click(TObject *Sender);
{
// do one action...
}
void __fastcall TForm1::Timer1Timer(TObject *Sender);
{
Button1Click(Button1);
// or:
// Button1->Click();
}
Quote
Inside the timers ONTimer, I could check if the button is still pressed
You do not need to do that.
Gambit
 

Re:checking if a button is down

Works nice!
I added the following to give the user a little pause before fast forwarding
takes place;
In OnTimer
if(Timer1->Tag>15)
ForwardBtnClick(Sender);
else
Timer1->Tag++;
and
in MouseUp I added
Timer1->Tag = 0;
-tk
 

{smallsort}