#Hey, so i wonder is there a signal that detects am i holding a button

1 messages · Page 1 of 1 (latest)

dim stump
#

Basically i want to find a signal that can detect if im holding a button. I only found ones that detects a click not holding

lone zenith
#

That's functionality you'll have to add yourself

dim stump
#

Oh, thanks

ruby sorrel
#

The mouse_entered signal is essentially a hovered signal as when your mouse enters it is hovered. Assuming you rely on mouse interaction for button usage.

solemn shell
#

Add this script to any Control node and it will print pressed/released, and for Button derived classes there are signals for it button_up and button_down

extends Control


func _gui_input(event: InputEvent) -> void:
    var mb: InputEventMouseButton = event as InputEventMouseButton
    if not mb:
        return
    if mb.button_index == MOUSE_BUTTON_LEFT:
        if mb.pressed:
            print("pressed")
        else:
            print("released")

ruby sorrel
solemn shell
ruby sorrel
solemn shell
ruby sorrel
#

ok buddy.

solemn shell
#

you can replace the _gui_input() method with button_down and button_up signals if you want. this will emit the signal holding(true) after 0.5 second of holding the button and will emit holding(false) if it was holding it

extends Control

signal holding(pressed: bool)

var timer: Timer = Timer.new()

var is_holding: bool


func _init() -> void:
    timer.one_shot = true
    add_child(timer)
    timer.timeout.connect(_on_timer_timeout)


func _on_timer_timeout():
    is_holding = true
    holding.emit(true)


func _gui_input(event: InputEvent) -> void:
    var mb: InputEventMouseButton = event as InputEventMouseButton
    if not mb:
        return
    if mb.button_index == MOUSE_BUTTON_LEFT:
        if mb.pressed:
            timer.start(0.5)
        else:
            if not timer.is_stopped():
                timer.stop()
            if is_holding:
                is_holding = false
                holding.emit(false)
ruby sorrel
#

Good lord, stop with that nonsense. There is a signal built in for their exact needs. They want to know if a button is held, the button_down signal provides exactly that.

solemn shell
ruby sorrel
#

Notice that the signal I provided is not the clicked signal they tried?

#

It is a button_held signal from the BaseButton class. entirely different and exactly what they asked for.

solemn shell
# ruby sorrel Notice that the signal I provided is not the clicked signal they tried?

it emits once you click the button and this is also what i suggested for him there and the same thing that you have told me that it's not what he is searching for, did you test the code i wrote ? or you see this ? For Button derived classes there are signals for it button_up and button_down

just lets all agree that we are trying to help here xD

ruby sorrel
#

When you hear hooves think horses not zebras.

solemn shell
ruby sorrel
solemn shell
#

it detects clicking and this is the same thing i have told him previously and the same thing you have told me it's not releated and made me realize that he already knows about it here I only found ones that detects a click not holding

#

Please try to help and if you want to argue about this we can continue in #💬┃casual-conversations

ruby sorrel
solemn shell
#

Please read the messages again

ruby sorrel
# solemn shell Add this script to any Control node and it will print pressed/released, and for ...

Pressed is not button down or button up, this script is unrelated, that was my point. You can't use an AI or whatever you did to provide a script that doesn't even use the information you gave above it.

After that you once again gave a complex script for a simple signal call.

Yes you gave the right signals, you didn't use them in your script.

That is the confusion you caused and the problem with what you've said. Hence why I provided only the signal for them which is what they asked for.

solemn shell
# ruby sorrel Pressed is not button down or button up, this script is unrelated, that was my p...

I have provided the same signal in my answers right before showing the script and have made it clear that it was intended to work with Control nodes, but you have been disrespectful and have spammed the chat with the same answer many times and i don't feel good about your behavior so I'm passing this to the <@&1235162294586048574>, We all are here to help and what you have been doing wasn't helpful at all.

ruby sorrel
#

Sorry you don't like being called out but you didn't use the proper signal in either script and caused undue confusion for a beginner. I was attempting to explain to you so you could learn why your answer wasn't what they wanted but alas you seem too arrogant to accept that.

I'll move on as I tried to do when I asked you to stop pinging me but for any moderation involved please consider what I've said. They gave an answer then heavily convoluted the OPs ability to understand it by providing unneeded scripts that don't use the functionality that was requested or mentioned.

Cheers

elfin grotto
#

considering OP wanted to tell when a button is being held, then your solution of just telling them to use the button_down is incorrect or incomplete, as it will fire regardless of whether the button is clicked and released or clicked and held down. presumably OP wants to know if a button was held for a certain duration of time, which would require pairing the button_down signal with a Timer node

@ruby sorrel regardless of your opinion regarding solutions provided by others, which you are fully entitled to, this doesn't give you the right to belittle them by acting unnecessarily confrontational and calling them "nonsense". this behavior will come across as hostile and won't lead to anything productive

ruby sorrel
#

That's reasonable. I struggle with social norms due to being autistic but I understand that's not okay so I will work harder to not belittle people for my opinions.

#

I do genuinely just want to help people learn I guess my frustration just came out in an unhealthy way, I can see that now. I'll move on and learn from this. Cheers

elfin grotto
#

thank you for understanding. as for @solemn shell , please also respect when people choose to exit a conversation or wish to not be pinged by replies anymore. this can be done by clicking the "@ ON" button when writing your reply. it will still link to the original message, but its author won't be pinged anymore

solemn shell