Can probably be simplified a bit!
Announcement
Collapse
No announcement yet.
Hold Mouse Button vs. Tap Mouse Button
Collapse
X
-
JayZone80 repliedAnother version if you want to trigger long click as soon as it reach the threshold instead of when releasing key.
Can probably be simplified a bit!
-
JayZone80 repliedI was looking for something like this, short long click detection, but found nothing so i made this macro!
Leave a comment:
-
Deathstick repliedHere's another different way of going about it that I made, it might not be the best for your case but it's what I currently do for handling detecting if the lmb is held down long enough for box selecting units.
Both in tick, not really the best way but since it's only on the player character I didn't really care. I also use enums to handle alot of things since there's so many different states the mouse can be in depending on if its used to build, select units, mark orders, etc.
Leave a comment:
-
dacabad repliedHowdy! Got a little lost in your last comment. You might want to try doing it with timers, as it can give you more control about this issue.
So the main idea is you set a timer to check if you have pressed the key longer than an user-defined threshold (HoldingThreshold variable). If that is the case, this sets a different timer in charge of pulsing your action (Tick event below the first timer). Once you release the key, it checks if you were holding (second timer was set) and in case not, it launches the function assigned to "pressed". Note that the first timer is supposed to launch only once, therefore the Looping bool is set to false.
I know it can be a little intrincate, but give it a try and let me know if it works for you.
Leave a comment:
-
kaleidosgu repliedOriginally posted by Nada88 View PostThere is a function called 'get input key time down' it will return the time a key has been pressed. You can then use a float>float comparison to see if the input time is longer than the float threshold, which can drive a branch.
only thing is that this function will return 0 if you call it on the frame the key is released, so you need to set a float with the input key time down every frame, which is basically the same as adding the deltatime each frame like tiskan mentioned
When I new a project it works. Is there any node or setting would forbid the mouse pressed?
Finally, I have found the issue. In project setting - input, you should set default viewport mouse capture mode as "capture pernanently including initial mouse down" then you can catch mouse down event at first pressed left mouse button.
Last edited by kaleidosgu; 03-10-2020, 01:49 AM.
Leave a comment:
-
Nada88 repliedThere is a function called 'get input key time down' it will return the time a key has been pressed. You can then use a float>float comparison to see if the input time is longer than the float threshold, which can drive a branch.
only thing is that this function will return 0 if you call it on the frame the key is released, so you need to set a float with the input key time down every frame, which is basically the same as adding the deltatime each frame like tiskan mentioned
Leave a comment:
-
SirMuttonChops repliedOriginally posted by Tiskan View PostYou will have to time iti think. Once the user presses the mousebutton, set a variable and increas it by delta time, check every frame if accumulated deltatime has reached your desired "hold time", if yes, fire the hold button down action. On button release check if accumulated deltatime is less than desired "hold time", if yes, fire the action user tapped the mouse button. I hope you get the gist of what i mean, sorry if little vague, but thats the only thing i could think of right now.
Leave a comment:
-
SirMuttonChops repliedOriginally posted by SkeetonYu View Post
Why wouldn't that work? When pressed make a bool that becomes true.
Make the bool false when release.
So now when is pressed make the bool true. Then add a delay. How ever long you want to check. Do a branch. Is the button release? (False) Then do tap logic. If it still true then do hold logic.
This doesn't work on its own because the "Pressed" Blueprints will try to resolve every time the button is pressed - regardless of whether it's being held or not. So, if a person just taps or holds, that first bit of logic will play out on both occasions. Without any input buffering, it does not allow the Released logic to play out.
Adding a delay doesn't account for, say, button mashing. If I make the hold for 1 second, an accidental double tap could trigger the hold. And even if it could, it would have to check that time regardless of whether you tap or hold the button because merely pressing it would trigger the check. So, there'd be a delay for any tap attacks added, as well.
Unreal really needs better input buffering support because the plugin on the Marketplace is not at all intuitive.
Leave a comment:
-
SkeetonYu repliedOriginally posted by SirMuttonChops View Post
That doesn't work.
Make the bool false when release.
So now when is pressed make the bool true. Then add a delay. How ever long you want to check. Do a branch. Is the button release? (False) Then do tap logic. If it still true then do hold logic.
- 1 like
Leave a comment:
-
Tiskan repliedYou will have to time iti think. Once the user presses the mousebutton, set a variable and increas it by delta time, check every frame if accumulated deltatime has reached your desired "hold time", if yes, fire the hold button down action. On button release check if accumulated deltatime is less than desired "hold time", if yes, fire the action user tapped the mouse button. I hope you get the gist of what i mean, sorry if little vague, but thats the only thing i could think of right now.
- 1 like
Leave a comment:
-
SirMuttonChops repliedOriginally posted by SkeetonYu View Post
Use the release for tap and use press for hold.
Leave a comment:
-
SkeetonYu repliedOriginally posted by SirMuttonChops View PostIs there a way that I can have one function tied to tapping the Left Mouse Button, but having a different action occur if the left mouse button is held?
For example, if a player taps the Left Mouse Button, their character will swing their sword. But if the player holds the mouse button, the character will kick their opponent. I know I could easily just switch that to another button, but I want to know how holding a button will work because it's more practical for the mechanics I have in mind.
Leave a comment:
-
SirMuttonChops started a topic Hold Mouse Button vs. Tap Mouse ButtonHold Mouse Button vs. Tap Mouse Button
Is there a way that I can have one function tied to tapping the Left Mouse Button, but having a different action occur if the left mouse button is held?
For example, if a player taps the Left Mouse Button, their character will swing their sword. But if the player holds the mouse button, the character will kick their opponent. I know I could easily just switch that to another button, but I want to know how holding a button will work because it's more practical for the mechanics I have in mind.Tags: None
Leave a comment: