Source language: Translate to:

Detect a doubleclick

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Detect a doubleclick

Postby cipolla » Fri Jan 30, 2004 7:32 am

Hi folks,

for a new project i have the need to detect a double mouseclick on a button (or even on a selfmade button using the PictureObject)

I put some code together and it is working ok, but i think there could be some other solution (or a plugin that i don´t know) posted befor or someone else has a better idea.

here is what i have done:

Action Script used in a simple Button:

...you could use for example a track bar to setup the double click speed
SetVar "[clickSpeed]" "2"
SetVar "[dclick]" ""
SetVar "[click]" "[Click]+1"
If "[click]" "=" "2"
 GotoLine "DoubleClick"
EndIf
Delay "[ClickSpeed]*100"
If "[dclick]" "=" "1"
 GotoLine "End"
EndIf
...to prevent a next click DisableObject could be a good idea
DisableObject "[Self]"
SetVar "[click]" "0"
AlertBox "MouseClick" "Normal Click detected"
...put your code here
EnableObject "[self]"
Return

:DoubleClick
...to prevent a next click DisableObject could be a good idea
DisableObject "[Self]"
AlertBox "MouseClick" "Double Click detected!"
SetVar "[dclick]" "1"
SetVar "[click]" "0"
...put your code here

:end
EnableObject "[self]"

It would be nice if someone could try this out. Maybe someone (GK51, GKCS or Sam...) has something better in their drawer.

Many greetings
Klaus
cipolla
 

Detect a doubleclick

Postby GKCS » Fri Jan 30, 2004 9:48 am

Klaus,

how often do you check your E-Mail account empics@web.de

It does not make sense, to mail you something to this account, incase of no respond .....

G.
GKCS
 

Detect a doubleclick

Postby cipolla » Fri Jan 30, 2004 9:52 am

you got mail!
cipolla
 

Detect a doubleclick

Postby Gaev » Fri Jan 30, 2004 12:03 pm

Klaus:

I tried out your suggested solution ; only I ...

a) slowed things down (with SetVar "[clickSpeed]" "20" ) so I could observe what code snippet was being executed.
b) replaced the AlertBox commands with SetVar SetVar "[clog]" "[clog]x.." (where x is c or d) ; responding to the AlertBox itself consumes time and might skew the results ; I also placed a TextBox with its content set to [clog] so I could see the sequence of events.

... you might try doing the same as I found unexpected results when I followed a DoubleClick with another click ; from examining [clog], it seemed that one DoubleClick and two Click events were recognised ; a user might not perform this sequence of clicks but you might want to check this out. Also, I did not test your code with 2 buttons, to see the imapct of clicking on different buttons in sequence ; again, this might not be an improbabble event in real life.

---------------

I took another approach ; one that uses a Timer object ; while just one such object can handle any number of buttons etc. with Click & DoubleClick events, the (minor) negative with the design is that the actual code to be executed has to be placed in a subroutine i.e. for object ButtonA, there would be onButtonAClick & onButtonADoubleClick subroutines.

I called my Timer object "CTimer" ; check property labelled "Wait for TimerStart action" ; the Timer Interval code snippet would be ...

TimerStop "CTimer"
SetVar "[CTimerStarter]" ""
SetVar "[clog]" "[clog]to_[CTimerStarter].."
GoSub "on[CTimerStarter]Click"

Return

For each object that you want Click & DoubleClick events recognised, place this code in the Click event (or you can just have a GoSub "MouseControl" ; and place the code as this subroutine).


If "[CTimerStarter]" "=" ""
SetVar "[clog]" "[clog]null.."
TimerStart "CTimer" "[DClickInterval]"
SetVar "[CTimerStarter]" "[self]"
Return
EndIf

If "[CTimerStarter]" "=" "[self]"
TimerStop "CTimer"
SetVar "[CTimerStarter]" ""
SetVar "[clog]" "[clog]d_[self].."
GoSub "on[CTimerStarter]DoubleClick"
Return

Else
TimerStop "CTimer"
SetVar "[clog]" "[clog]c_[CTimerStarter].."
GoSub "on[CTimerStarter]Click"
SetVar "[CTimerStarter]" ""

SetVar "[clog]" "[clog]f_[self].."
SetVar "[CTimerStarter]" "[self]"
TimerStart "CTimer" "[DClickInterval]"
Return

EndIf


Note1: Once finished testing, all commands that reference [clog] can be commented out.
Note2: In your Book Start section SetVar "[DClickInterval]" "2000" (while testing) and something like "50" to "200" in production.

Logic:
a) Normally, the Timer is stopped ; this is indicated by [CTimerStarter] = null.
b) When user clicks an object in this state, the Timer is started & [CTimerStarter] = name of this object.
c.1) If user does not click again for [DClickInterval], the Timer object will pop ; this will cause it to stop itself, set [CTimerStarter] = null and invoke the object's Click event processing routine called onXXXXClick (where XXXX is the name of the object).
c.2) If user clicks again before [DClickInterval) has expired, the Timer object is (pre-maturely) stopped, [CTimerStarter] is set to null again and onXXXXDoubleClick is invoked.
c.3) If (a really fast) user clicks another object before [DClickInterval) has expired, the onXXXXClick event must first be executed ; then, the Timer needs to be restarted with the current object as the [CTimerStarter] ... so later, either (c.1) or (c.2) is invoked for this object.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Detect a doubleclick

Postby cipolla » Sat Jan 31, 2004 5:49 am

Hello GK,

thanks for the work on that. I pasted your code into my publication and wonder, it does not work.

ok, after taking a deeper look in the code i noticed that there was something wrong with the [CTimerStarter] variable.

In your code you cleared the [CTimerStarter] befor the GoSub action is called. so i set the clear command after the GoSub and now it is working as descriped. I think this is a good work and it is more usable than my script.

The only thing i added for me is to Disable the button when executing the code to avoid a new user click befor the accordant actions are finished.

Here is the code without the debugging logs and (as i think) in correct order:

For the initialization:
[color=blue]
SetVar "[DClickInterval]" "200"
[color=black]
For the Timer object:
[color=blue]
TimerStop "[Self]"
GoSub "on[CTimerStarter]Click"
 SetVar "[CTimerStarter]" ""
Return
[color=black]
and in the button action:
[color=blue]
If "[CTimerStarter]" "=" ""
  TimerStart "CTimer" "[DClickInterval]"
  SetVar "[CTimerStarter]" "[self]"
  Return
Else
  TimerStop "CTimer"
     GoSub "on[cTimerStarter]DoubleClick"
       SetVar "[CTimerStarter]" ""
     Return
EndIf
[color=black]
I think the last else command is optional, because i tested it several times and was not able to execute another script before [DClickInterval] has expired.

Good values for the [DClickInterval] are between 180 and 300 Milleseconds.

Again, thanks alot for the great job. This should be part of the code snippet bank.

Greetings from Germany
Klaus
cipolla
 

Detect a doubleclick

Postby Gaev » Sat Jan 31, 2004 9:08 am

Klaus:

In your code you cleared the [CTimerStarter] befor the GoSub action is called. so i set the clear command after the GoSub and now it is working as descriped

Sorry ! Serves me right for making those cosmetic changes AFTER I finished testing ; thanks for catching the error.


Looking at your (nicely) color coded solution, I am not sure if TimerStop "[Self]" should not be TimerStop "CTimer" ; unless i am missing something.


because i tested it several times and was not able to execute another script before [DClickInterval] has expired

I wasn't either ; but my philosophy is "If something can go wrong, it will ... and at the most inopportune time ... :-)) ; e.g. if someone had some kind of scripted mouse-emulation routine, it might be possible to misinterpret two quick clicks (on two different objects) as a DoubleClick (on the first object) ; but I agree, it is highly improbable.

Thanks again.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Detect a doubleclick

Postby GKCS » Sat Jan 31, 2004 11:33 am

A very short way, to detect a double-click on any object, without a timer and unique for every object!

Add the following code to the objects OnClick Action:

Math "[Button1]+1" "0" "[Button1]"
   If "[Button1]" ">" "1"
       playtone "440"
       return
   endif
delay "250"
setvar "[Button1]" ""

Replace the PlayTone with any DoubleClick action, e.g. a call or gosub ....

The delay indicates, how sensitive the object will react on double-click.

The trick is, the same script can start a 2. time, before the 1. script-cylcle finished.

On this way, it is very easy, to implement a double-click to every object, which offers an OnClick action. Buttons also can do an OnDoubleRightMouseClick .....

The only thing you have to take care is, choose the right variable names, unique for every object .....

G-))

(Edited by GKCS at 1:34 pm on Jan. 31, 2004)
GKCS
 

Detect a doubleclick

Postby Gaev » Sat Jan 31, 2004 12:52 pm

GKCS:

Perhaps you took a narrow definition of Klaus's original requirement that i have the need to detect a double mouseclick on a button ; as you state at the start of your post A very short way, to detect a double-click on any object, the routine does that ... BUT isn't it at the expense of not recognising a (single) click event for the same object ? ... or am I missing something ?

let me try this scenario ...

User clicks on object ; [Button] becomes 1 ; If ... EndIf is bypassed ; there is a 250 mSec delay ; [Button] becomes null ... no response to a single click event.

You could place the single click event code after the last command in your posted routine ... but then, when a user double clicks, the first clicks will still trigger the single click commands (albeit after a 250 msec delay).

I may be mistaken, but the request to resond to a double click would be "in addition" to being able to respond (with a different set of actions) to a single click ; otherwise, why make the user double click when a single click will do.

I look forward to your response.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Detect a doubleclick

Postby GKCS » Sat Jan 31, 2004 1:10 pm

GK51,

surely, it doesn´t make sense, to detect double click, while single click does not work either ......

But where is the problem?

A little modification will do the trick again :-)


Math "[Button1]+1" "0" "[Button1]"

   If "[Button1]" ">" "1"
       playtone "440"
       return
   endif

delay "250"

   if "[Button1]" "=" "1"
       playtone "880"
   endif

setvar "[Button1]" ""

The 2. IF-construction just handles the single-click action of the object ......

So on this way,you easily can handle single also than double-click ActionCommands very well ....

G-))
GKCS
 

Detect a doubleclick

Postby djold1 » Sat Jan 31, 2004 1:47 pm

I am impressed with the ingenuity that all of you have shown in creating a situation where a double-click is sensed. On the other hand, I am appalled at the amount of time and energy that was expended and the amount of code that is required to to do something that is a standard feature of almost all Windows applications.

The use of double-click is similar to the use of right-click which we got in NeoBook sometime ago for buttons only. While the use of work-arounds is justified for specialty or seldom used operations, double-click is mainline and should be a tab, at least on buttons, if not for all appropriate tools.

I would also like to see the number of places where right-click may be used extended as well..

One man's opinion..
djold1
 

Detect a doubleclick

Postby GKCS » Sat Jan 31, 2004 2:47 pm

Hi Pete,

are 10 lines of simple code really too much? It is just a result of 2 min. typing and thinking .....
Very often, reading Windows-Help for checking some "standard features" does take much more time :-)

G.
GKCS
 

Detect a doubleclick

Postby djold1 » Sat Jan 31, 2004 3:03 pm

GKCS..

As I read your code, which is nice, there is a problem if you have more than one button that is active with double-click. If I am not mistaken, if you have more than one button then you have to add some code and treat it as a subroutine.

Again, none of this is terrible. It just seems to me to be double-click should be standard in NeoBook since it is such a basic and useful operation.

(Edited by djold1 at 1:04 am on Feb. 1, 2004)
djold1
 

Detect a doubleclick

Postby GKCS » Sat Jan 31, 2004 3:12 pm

Hi Pete,

you are indeed wrong. No problems with many buttons .... the ONLY thing you have to take care is, to use different variables for every object (But that´s NO MUST, that´s ONLY for better readability)

e.g. [Button1] for Button1, [Button2] for Button2, [Button3] for Button3 ......

But I already mentioned that in my first posting !!!

If you use just the SAME code for different buttons (same ClickTrigger variable), it ALSO works very fine, because the scripts are ONLY executed by the corresponding button. And HOW realistic is it, to remove a mouse from one object to another one during time of double-click????

And if you don´t like that all, let the code be modified by itself.

**********

Math "[OnClick[Self] ]+1" "0" "[OnClick[Self] ]"
   If "[OnClick[Self] ]" ">" "1"
       playtone "440"
       return
   endif

delay "250"

   if "[OnClick[Self] ]" "=" "1"
       playtone "880"
   endif

setvar "[OnClick[Self] ]" ""

**********

And everything works very well :-)) Just try it ....


G-)))


(Edited by GKCS at 8:24 am on Feb. 1, 2004)


(Edited by GKCS at 8:27 am on Feb. 1, 2004)
GKCS
 

Detect a doubleclick

Postby rcohen » Sat Mar 06, 2004 4:03 pm

I suspect that double clicks are forthcoming, however with THIS code, we can have triple and quadruple clicks as options too ;-)

rcohen

(Edited by rcohen at 6:04 pm on Mar. 6, 2004)
rcohen
 

Detect a doubleclick

Postby NeoSoft Support » Mon Mar 08, 2004 3:29 pm

Quadruple clicks! I can't believe that Bill Gates hasn't thought of that yet!
NeoSoft Support
 

Next

Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest