Home AMX User Forum AMX General Discussion

HOWTO: Double Push!!

A very simple function, but I consider it a good idea since most people used to the concept of Double Click, so why not having a Double Push

It still need more modifications
Any contributions are welcomed, and I will update the main post

Thanks
DEFINE_FUNCTION INTEGER fnDblPush(INTEGER nBUTCHAN)
{
  //nDBBUTTONS[] an array to indicate first or second push for a range of input channels
  //lDBBUTTONSTIMERS1 an array to store at what instant a channel has been pushed
  //lDBBUTTONSTIMERS2 another array to store at what instant a channel has been double pushed
  IF(DBBUTTONS[BUTCHAN]=1)//If it was pushed before??
  {
    DBBUTTONS[BUTCHAN]=2//make this the second push
  }
  ELSE//if it was pushed twice before??
  {
    DBBUTTONS[BUTCHAN]=1 //make it the first push
  }
  SWITCH(DBBUTTONS[BUTCHAN])//Now.... Which push is it??
  {
    CASE 1://FIRST push
    {
      DBBUTTONSTIMERS1[BUTCHAN]=GET_TIMER //what time is it now?
    }
    CASE 2:// SECOND push
    {
      DBBUTTONSTIMERS2[BUTCHAN]=GET_TIMER//what time is it now?
    }
  }
  //If the time interval between the first and second push OR the second and first push is less than 6 tenths of seconds
  IF((DBBUTTONSTIMERS2[BUTCHAN]-DBBUTTONSTIMERS1[BUTCHAN])<6 OR (DBBUTTONSTIMERS1[BUTCHAN]-DBBUTTONSTIMERS2[BUTCHAN])<6)// then it is a DOUBLE push
  {
    RETURN 1
  }
  ELSE
  {
    RETURN 0 //single push
  }
}
BUTTON_EVENT[dvTP,1]
{
  PUSH:
  {
    LOCAL_VAR INTEGER DOUBLED
    DOUBLED = DB(BUTTON.INPUT.CHANNEL-40)
    SWITCH(DOUBLED)
    {
      CASE 1:
      {
	//DOUBLE PUSH ACTION
      }
      CASE 0:
      {
	//SINGLE PUSH ACTION
      }
    }
  }
}

Comments

  • a_riot42a_riot42 Posts: 1,624
    I find users have trouble with double clicks and double pushes, and I struggle with double clicks often enough as well, and end up renaming something when I didn't mean to. But for the odd time it makes sense I think I would do something like this:
    button_event[dvUI, iButton]
    {	
      push:
      {
        if (isSecondPush)
        {
          cancel_wait 'Double Push Wait'
          send_command 0, "'Just received a double push.'"
          isSecondPush = 0
        }
        else
        {
          isSecondPush = 1
          wait 5 'Double Push Wait'
          {
            isSecondPush = 0
            send_command 0, "'Just received a single push.'"
          }
        }
      }
    }
    
    
Sign In or Register to comment.