You would want to use it for those occasions where you want to administer an object (such as setting up an access list, running a configuration utility, perform window tinting, etc) with a mouse touch, but you want to filter out unintentional random clicks.
Currently the code restricts access to the objects owner (in two locations - touch_start and touch). It would make sense to encapsulate the access check to a separate function and add an additional test in the listen event as well for greater security. A 2nd expansion would add a configuration variable to switch between owner, group, and public access.
CODE
// set these to whatever values you wish
integer myChannel = 123;
float trigger_time = 2.0;
float idle_time = 10.0;
list menu = ["A", "B"];
// used for controlling command entry
float elapsed = 0.0;
integer listenHandle;
A()
{
llSay(0, "A Pressed");
}
B()
{
llSay(0, "B Pressed");
}
touch_hold()
{
elapsed = llGetAndResetTime();
llListenControl(listenHandle, TRUE); // ...enable
llSetTimerEvent(idle_time);
llDialog(llDetectedKey(0), "Menu Stub", menu, myChannel);
}
default
{
state_entry()
{
listenHandle = llListen(myChannel,"","","");
elapsed = 0.0;
}
on_rez(integer startup_param)
{
llResetScript();
}
touch_start(integer num_detected)
{
if (llDetectedKey(0) == llGetOwner()) {
elapsed = llGetAndResetTime();
}
}
touch(integer num_detected)
{
if (llDetectedKey(0) == llGetOwner()) {
elapsed = llGetTime();
if (elapsed > trigger_time) {
touch_hold();
}
}
}
timer()
{
llSetTimerEvent(0.0);
llListenControl(listenHandle, FALSE); // ...disable
}
listen(integer chan, string name, key id, string cmd)
{
if (llListFindList(menu, [cmd]) != -1) {
if (llToUpper(cmd) == "A") {
A();
}
else if (llToUpper(cmd) == "B") {
B();
}
}
}
}