Holding a key

hi everyone,
I need to know how can I create a Common event (for example) that the player has to activate holding a key for some seconds, like pressing Shift for 3 seconds. I'm pretty sure that I need a Plugin but I didn't find one. I just found this https://fallenangelolivia.itch.io/skip-cutscene-plugin plugin where you have to hold a key to skip a cutscene, but it can't help me.
Thank you
This is the script code for holding a key: Input.isPressed(key). You can use that in a conditional branch, fourth page -> script call. Here's an example for holding the ok button (Z, Enter):
Input.isPressed("ok")
This condition returns true EVERY FRAME that the key is pressed (held down).
Event that the player has to activate holding a key for some seconds, like pressing Shift for 3 seconds.
No plugin needed really... one way to do this without a plugin... would be...
Spoiler: Use a switch and a parallel common event
1584464900087.png
Spoiler: Just turn the switch on to activate
1584465525062.png
Spoiler: Default Key List for your reference
1584465167994.png
Or with only event commands, e.g.
Spoiler: Event example
Code:
◆Comment:Say hi!
◆Text:None, Window, Bottom
:    :Hold the shift button down for three seconds!
◆Comment:Initialise the variables and stuff~
◆Control Variables:#0001 Hold Time = 0
◆Control Variables:#0002 Time Limit = 300
◆Control Switches:#0001 Success = OFF
◆Loop
  ◆Comment:Check input (Conditional Branch > page 3 > Button)
  ◆If:Button [Shift] is pressed down
    ◆Comment:+1 to time held
    ◆Control Variables:#0001 Hold Time += 1
    ◆
  :Else
    ◆Comment:Key released, reset hold time
    ◆Control Variables:#0001 Hold Time = 0
    ◆
  :End
  ◆Comment:If button is held for 180+ frames (3 seconds), end loop
  ◆If:Hold Time ≥ 180
    ◆Control Switches:#0001 Success = ON
    ◆Break Loop
    ◆
  :Else
    ◆Comment:Count down another frame from time limit
    ◆Control Variables:#0002 Time Limit -= 1
    ◆Comment:If player has taken too long, end loop
    ◆If:Time Limit ≤ 0
      ◆Break Loop
      ◆
    :Else
      ◆Comment:Otherwise, wait for next frame to check again
      ◆Wait:1 frame
      ◆
    :End
    ◆
  :End
  ◆
:Repeat Above
◆Comment:Check switch to determine response!
◆If:Success is ON
  ◆Text:None, Window, Bottom
  :    :Nice work!
  :    :Shift key was held for three seconds!
  ◆
:Else
  ◆Text:None, Window, Bottom
  :    :Time's up! Better luck next time.
  ◆
:End
I've included a "limit" here as well, just for demonstration purposes: you get 5 seconds (300 frames) in which to hold the Shift key down for 3 consecutive seconds (180 frames). 🙏
Or with only event commands, e.g.
Spoiler: Event example
Code:
◆Comment:Say hi!
◆Text:None, Window, Bottom
:    :Hold the shift button down for three seconds!
◆Comment:Initialise the variables and stuff~
◆Control Variables:#0001 Hold Time = 0
◆Control Variables:#0002 Time Limit = 300
◆Control Switches:#0001 Success = OFF
◆Loop
  ◆Comment:Check input (Conditional Branch > page 3 > Button)
  ◆If:Button [Shift] is pressed down
    ◆Comment:+1 to time held
    ◆Control Variables:#0001 Hold Time += 1
    ◆
  :Else
    ◆Comment:Key released, reset hold time
    ◆Control Variables:#0001 Hold Time = 0
    ◆
  :End
  ◆Comment:If button is held for 180+ frames (3 seconds), end loop
  ◆If:Hold Time ≥ 180
    ◆Control Switches:#0001 Success = ON
    ◆Break Loop
    ◆
  :Else
    ◆Comment:Count down another frame from time limit
    ◆Control Variables:#0002 Time Limit -= 1
    ◆Comment:If player has taken too long, end loop
    ◆If:Time Limit ≤ 0
      ◆Break Loop
      ◆
    :Else
      ◆Comment:Otherwise, wait for next frame to check again
      ◆Wait:1 frame
      ◆
    :End
    ◆
  :End
  ◆
:Repeat Above
◆Comment:Check switch to determine response!
◆If:Success is ON
  ◆Text:None, Window, Bottom
  :    :Nice work!
  :    :Shift key was held for three seconds!
  ◆
:Else
  ◆Text:None, Window, Bottom
  :    :Time's up! Better luck next time.
  ◆
:End
I've included a "limit" here as well, just for demonstration purposes: you get 5 seconds (300 frames) in which to hold the Shift key down for 3 consecutive seconds (180 frames). 🙏
Yepperz almost showed that way too lol
but only problem is it isn't generally as flexible to alter in the future needs if using in bulk and not as easy to control whether or not the player can still move or not. (in my example set the common event to autorun instead of parallel to stop player movement)

Definitely worth mentioning the way you have shown though too 🙂👍
And the extra bonus of a time limit without using a game timer, nice touch 😉
I feel like the main strength of my approach is that it shows the logic without resorting to scripting. Also, it applies almost equally to a variety of QTE-like situations: button-holding, button-mashing, mixed input, etc. 🙂

Also, yes, I dislike using the built-in timer for anything other than display purposes. Personal preference. 😛
but only problem is it isn't generally as flexible to alter in the future needs if using in bulk and not as easy to control whether or not the player can still move or not. (in my example set the common event to autorun instead of parallel to stop player movement)
Spoiler: Comparison of approaches
By "using in bulk", I assume you mean different hold/window times? That can be achieved with an additional variable, e.g. "Max Hold Time" and use that for the reset value; just set it before activating the common event. 😮‍💨

If you're referring to different buttons, then yes, for my approach that'd require making separate checks for each button; could be done by making a generic event that determines the input check by referencing a variable set beforehand, but not particularly elegant. With a scripted branch like yours, I see you could just pass it a text variable or something if necessary, and set that variable before activating the event. 🙏

If you're referring to the fact that certain commands do not accommodate variable inputs (e.g. Move Picture cannot scale to variable size or move over a variable duration) then you have a point, but variable scaling/duration is not necessary in order to create a variable gauge; for instance, you can use variables for pointer positioning (timeout, hold time, etc). That is much easier if you have some relevant variables already set up, though, as in my approach. 😅

Like you say, controlling player movement is entirely down to the event's trigger, independent of its contents: it applies equally to both our approaches. 😴

My approach exposes an exploit: if you start holding Shift during the original prompt, it's trivial to "win". This can be resolved by adding a second input window immediately before the first, e.g.
Spoiler: Extended event example
Code:
◆Comment:Instructions
◆Show Picture:#1, icon, Center (408,75), (100%,100%), 255, Normal
◆Text:None, Window, Bottom
:    :Hold the shift key for 3 seconds
:    :while this picture is visible!
◆Erase Picture:#1
◆Text:None, Window, Bottom
:    :Holding shift when it is not shown
:    :will count as a fail.
:    :
:    :\!Ready...\.set...\.GO!\.\^
◆Comment:1 second of no input
◆Control Switches:#0001 Success = ON
◆Control Variables:#0001 Input Time = 60
◆Loop
  ◆Comment:Check input
  ◆If:Button [Shift] is pressed down
    ◆Comment:NOPE
    ◆Control Switches:#0001 Success = OFF
    ◆Break Loop
    ◆
  :Else
    ◆Control Variables:#0001 Input Time -= 1
    ◆If:Input Time ≤ 0
      ◆Comment:Time's up!
      ◆Break Loop
      ◆
    :Else
      ◆Comment:Check again next frame
      ◆Wait:1 frame
      ◆
    :End
    ◆
  :End
  ◆
:Repeat Above
◆Comment:If successful (no input) then move to phase 2: hold for 3 seconds!
◆If:Success is ON
  ◆Comment:Show input prompt
  ◆Show Picture:#1, icon, Center (408,75), (100%,100%), 255, Normal
  ◆Control Variables:#0001 Input Time = 0
  ◆Comment:Can alternatively initialise Time Limit variable before activating this event
  ◆Control Variables:#0002 Time Limit = 300
  ◆Control Switches:#0001 Success = OFF
  ◆Loop
    ◆Comment:Check input
    ◆If:Button [Shift] is pressed down
      ◆Comment:+1 to time held
      ◆Control Variables:#0001 Input Time += 1
      ◆
    :Else
      ◆Comment:Key released, reset hold time
      ◆Control Variables:#0001 Time = 0
      ◆
    :End
    ◆Comment:End loop if button held for 180+ frames, else wait for next frame
    ◆If:Input Time ≥ 180
      ◆Control Switches:#0001 Success = ON
      ◆Break Loop
      ◆
    :Else
      ◆Comment:Count down another frame from time limit
      ◆Control Variables:#0002 Time Limit -= 1
      ◆Comment:End loop if player has taken too long
      ◆If:Time Limit ≤ 0
        ◆Break Loop
        ◆
      :Else
        ◆Wait:1 frame
        ◆
      :End
      ◆
    :End
    ◆
  :Repeat Above
  ◆Comment:Erase picture afterwards~
  ◆Erase Picture:#1
  ◆If:Success is ON
    ◆Text:None, Window, Bottom
    :    :Nice work!
    :    :Shift key was held for three seconds!
    ◆
  :Else
    ◆Text:None, Window, Bottom
    :    :Time's up! Better luck next time.
    ◆
  :End
  ◆
:Else
  ◆Text:None, Window, Bottom
  :    :Too early!
  ◆
:End
I didn't include this in my original example partly because it makes the whole thing look more intimidating and possibly harder to follow. However, in hindsight this is a pretty standard situation (especially the input prompt thing), so I probably should have originally included it. 😅

Note that your approach has a quirk: keep Shift held down. Now press, say, the action button to activate [an event that activates] your event. The latest button will now no longer be Shift, you'll have to release it and start holding again from scratch. Not sure if that's intentional, or an acceptable side-effect, just thought I'd point it out~ 👋
No plugin needed really... one way to do this without a plugin... would be...
Hello, i was trying to do it in the way you do but when i hold the shift button notting happens...

I have wrote the same lines, here are some screenshots (I have the maker program in spanish but it is the same):

Spoiler: Common event
3.png

In the map i created an event like this:

Spoiler: Map event (Activator Switch)
2.png

I got two cases...

In A ) With the common event set as parallel process it just nothing happens.
In B ) With the common event set as automatic the game freezes ( i think that maybe waiting the common event to end) but anyway nothing happens.

I would be grateful if you can help me 🙂

Original thread: https://forums.rpgmakerweb.com/threads/holding-a-key.119214/