[Resolved] Stop repeat detection of key press

Hey guys. I'm writing a script where you cycle through a list of possible targets with the [Q] and [W] keys. However, I'm having a bit of a problem, because when I so much as look at [Q], it cycles through the whole list. The problem is that the script only detects if the key is down, and doesn't wait for it to be released before detecting again.

I was wondering if there was a way to still have it so that it cycles through the list when the key is pushed down, but then wait for it to be released after before taking another reading.

I'd also like to know how RPGMakerXP does this with the Inventory screen. The game goes to the inventory screen immediately when [Esc] is pressed, but if you keep it held down it doesn't go back to the map screen. It waits for you to release the [Esc] key before it will allow the detection to take you back to the Map Screen. I tried looking at the scripts and there doesn't seem any specific way it does this. Is it because it changes scene in between which somehow resets the detection?

Here's the method that I'm having the issues with.
  1.  #--------------------------------------------------------------------------
  2.   # * Cycle
  3.   #--------------------------------------------------------------------------
  4.   def VoodooDoll.cycle
  5.    # Cycle Forward
  6.     if (Input.press?(Input::R))
  7.       if (@cur >= @targets.length-1)
  8.         @cur = 0
  9.       else
  10.         @cur += 1
  11.       end
  12.       $game_player.center(@targets[@cur].x, @targets[@cur].y)
  13.       Input.update
  14.     # Cycle Backward
  15.     elsif (Input.press?(Input::L))
  16.       if (@cur <= 0)
  17.         @cur = @targets.length-1
  18.       else
  19.         @cur -= 1
  20.       end
  21.       $game_player.center(@targets[@cur].x, @targets[@cur].y)
  22.       Input.update
  23.     # Confirm
  24.     elsif (Input.press?(Input::C))
  25.       $game_player.moveto(@targets[@cur].x, @targets[@cur].y)
  26.       @mode = 1
  27.     # Cancel
  28.     elsif (Input.press?(Input::B))
  29.       $game_player.center($game_player.x, $game_player.y)
  30.       @mode = 0
  31.     end
  32.   end
Expand to see the code.
Use Input.trigger? instead of Input.press? .
Aha, wow. That was easy. Shoulda read up on my documentation. Thanks, Zer0!
HarryE wrote:
Aha, wow. That was easy. Shoulda read up on my documentation. Thanks, Zer0!


Actually, from what I remember, the documentation on the differences between trigger, repeat, and press is sketchy at best. The real difference is that press always returns true while the button is down, trigger only returns true when the button is pressed down, and not before or after, and repeat returns true as a combination of the above. To see what repeat is like, just try typing up a post and then hitting and holding a button. That's what it does.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=76164