Announcement

Collapse
No announcement yet.

Hold Mouse Button vs. Tap Mouse Button

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

  • replied
    Another 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!

    Click image for larger version

Name:	2020-12-01 04_18_22-Window.png
Views:	548
Size:	200.1 KB
ID:	1837899

    Leave a comment:


  • replied
    I was looking for something like this, short long click detection, but found nothing so i made this macro!
    Click image for larger version

Name:	2020-12-01 01_45_58-Window.png
Views:	555
Size:	67.2 KB
ID:	1837705 Click image for larger version

Name:	2020-12-01 01_46_26-Window.png
Views:	550
Size:	55.1 KB
ID:	1837706

    Leave a comment:


  • replied
    Here'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.
    Click image for larger version

Name:	01.PNG
Views:	2023
Size:	81.4 KB
ID:	1731425

    Click image for larger version

Name:	003.PNG
Views:	2022
Size:	183.9 KB
ID:	1731427
    Attached Files

    Leave a comment:


  • replied
    Howdy! 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.

    Click image for larger version

Name:	click.PNG
Views:	2046
Size:	139.4 KB
ID:	1731333

    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:


  • replied
    Originally posted by Nada88 View Post
    There 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
    I have tried to use GetInputKeyTimeDown to get LeftMouseButton, it dose not work. But when I double click the left mouse button it works. I mean if you click twice and hold the button at the second time you will get the result when you listening left mouse button.
    Click image for larger version  Name:	UEIssue.png Views:	0 Size:	294.8 KB ID:	1730865

    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.
    Click image for larger version

Name:	UEIssue2.png
Views:	2029
Size:	56.8 KB
ID:	1730940
    Last edited by kaleidosgu; 03-10-2020, 01:49 AM.

    Leave a comment:


  • replied
    There 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:


  • replied
    Originally posted by Tiskan View Post
    You 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.
    I think I understand what you're saying. So pressing creates a variable, X, that tracks the time the button is held. Releasing checks that time - if it is less than X, trigger one set of actions. If it is greater, do the other action. im not 100% sure it'll work, and having to do on-tick events for a combat action in a multiplayer PvP game hopefully doesn't weigh the game down too much... haha

    Leave a comment:


  • replied
    Originally 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.
    The original reply was splitting the actions to Pressed vs. Released.

    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:


  • replied
    Originally posted by SirMuttonChops View Post

    That doesn't work.
    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.

    Leave a comment:


  • replied
    You 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:


  • replied
    Originally posted by SkeetonYu View Post

    Use the release for tap and use press for hold.
    That doesn't work.

    Leave a comment:


  • replied
    Originally posted by SirMuttonChops View Post
    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.
    Use the release for tap and use press for hold.

    Leave a comment:


  • started a topic Hold Mouse Button vs. Tap Mouse Button

    Hold 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.
Working...
X