Jump to content
Sign in to follow this  
revochen Mayne

single/double click detection

Recommended Posts

This script detects if it gets touched once or twice within a short period of time.

 

float touchTime = 0.3;


list touchKeys = [];
list touchTypes = [];

default
{

    touch_start(integer total_number)
    {
        key who = llDetectedKey(0);
        if(llListFindList(touchKeys,[who])==-1)
        {
            touchKeys += who;
            touchTypes += "singleTouch";
            llSetTimerEvent(touchTime);
        }
        else
        {
            integer i = llListFindList(touchKeys,[who]);
            touchTypes = llListReplaceList(touchTypes,["doubleTouch"],i,i);
        }
    }
    
    timer()
    {
        integer i = 0;
        integer m = llGetListLength(touchKeys);
        llSetTimerEvent(0);
        while(i<m)
        {
            if(llList2String(touchTypes,i)=="singleTouch")
            {
                // do something on single touch
                llSay(0, "Thanks for your single touch "+llKey2Name(llList2Key(touchKeys,i))+"!");
            }
            else
            {
                // do something on double touch
                llSay(0, "Thanks for your double touch "+llKey2Name(llList2Key(touchKeys,i))+"!");
            }
            ++i;
        }
        touchKeys = [];
        touchTypes = [];
    }
}

 

 

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...