controller-lib icon indicating copy to clipboard operation
controller-lib copied to clipboard

Detecting if an individual button has been released.

Open AsixJin opened this issue 6 years ago • 1 comments

Is there any way to determine if an individual button has been released? The way I understand it you can only handle when no button is being pressed ie the user isn't touching the view.

AsixJin avatar Jun 13 '18 20:06 AsixJin

Cache the old value and check if it changed:

static uint32_t oldButtonValues = 0;
void buttonCallback(uint32_t newButtonValues){
   for(uint8_t shift = 0; shift < 32; shift++){
      if(oldButtonValues & (1 << shift) && !(newButtonValues & (1 << shift))){
         //released
      }
      else if(!(oldButtonValues & (1 << shift)) && newButtonValues & (1 << shift)){
         //pressed
      }
   }
   oldButtonValues = newButtonValues;
}

Convert to Java as needed. The onInputEvent is likely called whenever a finger is pressed released or moved.

meepingsnesroms avatar Apr 21 '19 17:04 meepingsnesroms