Announcement

Collapse
No announcement yet.

Input Held Down?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Input Held Down?

    Hello all. For input events, I see that there are outputs for Pressed and Released. How about when, say the left mouse button, is held down and having it continue to activate the output? If there is a way to detect that, is there a setting for the delay between each time the event is fired while it is held down, or would I need to use a delay?

    #2
    maybe a while loop and have a bool set to true when pressed, and set false when released?

    Comment


      #3
      Sounds like that should work. Thanks

      I'm surprised that there isn't an output for it. Kismet Input Events had it and would be really useful.

      Comment


        #4
        From the Get Player Controller node, you can use the Get Input Key Time Down node:

        Click image for larger version

Name:	HeldInput.jpg
Views:	1
Size:	12.4 KB
ID:	1049869

        The the input you are checking against is set with the Key input and the return value is 0 if the key is up or the cumulative time the key has been held otherwise. You can set up comparison that returns a boolean and use that to power a Branch or WhileLoop, which ever you want to use.

        Hope that helps out!

        -Steve

        Comment


          #5
          I went with the while loop approach, but the editor seems to hang indefinitely when ever the bool for the while loop is set to true. Any ideas what is going on?

          Last edited by hyawatha15; 03-21-2014, 10:40 PM.

          Comment


            #6
            I apologize, this is actually a bad setup to actually use with a WhileLoop, didn't mean to direct you to use it in this case--the WhileLoop expects that the exit condition to kick out of loop rests somewhere inside of the Loop Body, which won't be the case in your scenario. Here's one way you can setup what you're wanting to do:



            Pressing or Releasing F will toggle the IsCharging boolean to true or false. Event Tick fires off every frame and checks to see if you are holding down the F key (represented by the Branch checking the IsCharging boolean). If you are still holding the key down, it sets the Hold Time value to be the time you've been holding down the F key (from the same function I mentioned above). If you release the F key, it then prints out the final Hold time.

            Sorry for the confusion!
            Attached Files
            Last edited by Straxus; 03-21-2014, 11:08 PM. Reason: better screenshot

            Comment


              #7
              No worries! Thanks so much for the setup. Much appreciated.

              edit: Just tried it and it worked perfectly!
              Last edited by hyawatha15; 03-21-2014, 11:10 PM.

              Comment


                #8
                Added a better screenshot, last one was hard to read.

                Comment


                  #9
                  Can we do this with an InputAction rather than a key? Not sure if I'm missing something but I don't see a Get Input Action Time Down
                  Impromptu Games|dev blog|twitter|itch.io store|Patreon
                  Impromptu Procedural Ladders|Impromptu Procedural Handrails|Impromptu Procedural Stairs
                  |Impromptu Fire Propagation|InFlux Example Game|Impromptu Vector Field Painter

                  Comment


                    #10
                    There currently isn't any way to do such a query. The reason being that unlike a key that has a direct relationship to the hardware, actions are dependent on what input components are on the stack.

                    Thinking out loud about it a bit we could make that function look at the context's input component and track the press start time on the action binding similarly to how the axis value is stored on the action binding. I'll put in a task to look in to doing this.

                    In the mean time your best bet is probably to make a variable and on pressed open a gate or something similar such that you increment it by delta time in each tick. On released set the variable to 0 and close the gate.

                    Comment


                      #11
                      You can test if a key is pressed like this. Here I'm doing this on tick.

                      Click image for larger version

Name:	IsKeyDown.JPG
Views:	1
Size:	40.3 KB
ID:	1049889

                      Comment


                        #12
                        Originally posted by Marc Audy View Post
                        There currently isn't any way to do such a query. The reason being that unlike a key that has a direct relationship to the hardware, actions are dependent on what input components are on the stack.

                        Thinking out loud about it a bit we could make that function look at the context's input component and track the press start time on the action binding similarly to how the axis value is stored on the action binding. I'll put in a task to look in to doing this.

                        In the mean time your best bet is probably to make a variable and on pressed open a gate or something similar such that you increment it by delta time in each tick. On released set the variable to 0 and close the gate.
                        Hey just checking on this post to see if there has/will be any progress with a Held option for the input alongside the pressed/released options. I'm happy there are ways that we can do something similar atm, but it just seems like a lot of extra work/mess. Especially when it could be as simple as you suggested

                        Comment


                          #13
                          Originally posted by Wisdomcube2000 View Post
                          Hey just checking on this post to see if there has/will be any progress with a Held option for the input alongside the pressed/released options. I'm happy there are ways that we can do something similar atm, but it just seems like a lot of extra work/mess. Especially when it could be as simple as you suggested
                          Marc touched on this in his post where he mentioned axis binding. Beware that if you follow the approach I'm about to explain, you will end up with an event that is fired every frame, not just when the key is being held down! If you go under Edit/Project Settings/Engine/Input you should see a category called "Bindings". You can add your own axis mappings to the list by clicking on the plus sign next to it, and then specifying an input source (for instance, the 'F' key). You can also give it a name and a scale.


                          When you've mapped all your keys, save the project settings by clicking on "Set as Default", then open your blueprint. When you right-click in the graph view, you'll be able to find your new events under Input/Axis Events:

                          Comment


                            #14
                            Originally posted by ThomasKasene View Post
                            Marc touched on this in his post where he mentioned axis binding. Beware that if you follow the approach I'm about to explain, you will end up with an event that is fired every frame, not just when the key is being held down! If you go under Edit/Project Settings/Engine/Input you should see a category called "Bindings". You can add your own axis mappings to the list by clicking on the plus sign next to it, and then specifying an input source (for instance, the 'F' key). You can also give it a name and a scale.


                            When you've mapped all your keys, save the project settings by clicking on "Set as Default", then open your blueprint. When you right-click in the graph view, you'll be able to find your new events under Input/Axis Events:
                            Ah that worked! Never thought of doing it that way lol. Thanks for the help

                            Comment


                              #15
                              Can anybody help me create a similar action but i'm currently not having much luck with.
                              I want to create a charge effect when a key is held down, the longer its held for the greater the charge force is although I do want to clamp a maximum force say at 3 seconds you can't go beyond that strength.
                              For example you have simple box simulating physics, when you press space bar it adds force upwards and jumps. The longer you hold space the higher it jumps but when you reach 3 seconds you can't get any more charge.

                              Comment

                              Working...
                              X