I think I figured It Out. (note: in my mod, I added my own methods to detect inputs, so the code may need to be modified)
This method only runs the key detection function once, than waits for the key to be released before allowing it to run again. This means it should not return a double press if the user holds the key down. It also will not trigger, if the key is double tapped too slow (so the user pressing the key once, than pressing it again 10 minutes later, will Not trigger a double tap).
long startTime = System.currentTimeMillis();
boolean moveKeyPressed = false;
boolean keyEnabled = false;
@SubscribeEvent
public void onMove(InputUpdateEvent event){
boolean keyPressed = event.getMovementInput().backKeyDown;
if(!keyEnabled){
if(!moveKeyPressed && keyPressed){
long now = System.currentTimeMillis();
if(now > startTime + 300){
startTime = now;
}else{
keyEnabled = true;
// do stuff on double tap...
}
moveKeyPressed = true;
}else{ // optional
if(!moveKeyPressed && keyPressed && System.currentTimeMillis() > startTime + 300){
keyEnabled = false;
// do stuff to cancel double tap action if key is pressed again...
// useful if you need to allow the player to override the keypress and cancel the double tap action
}
}
// detect key release
if(!keyPressed){
moveKeyPressed = false;
}
}
}