Want to press a Button Widget from C++ or blueprint code.

Hello.

I have a Button Widget that is supposed to look like a numpad. What I would like is for the player to be able to interact with this numpad via clicking on the numbers with their mouse, or by pressing the numbers on their keyboard. I have this working currently, however, pressing the buttons with the mouse will transition the button from the Normal State to the Pressed State. I would like this little transition animation to play when the user pressed the numbers on their keyboard as well, but I cannot seem to figure out how to do this. Is there someway to update the button state and get this state transition from outside of the button?

Thank you.

hi,
i maybe this can help you … i do not know if it´s the best solution but it works :slight_smile:

quick demo

the red debug comes from the widget interaction component (just so you can see the keyboard presses, you can untick it in the component)… i made two (mouse,keyboard)

this is the main part… i put it in my camera pwn but you could make it a actor component too








this will be the main keypad widget


and this is just the button widget with an event dispatcher so you can bind ButtonClicked in the main widget


hope this helps you :slight_smile:

cheers :vulcan_salute:

建议你可以尝试有UMG蓝图控件来完成这个事情,里面自带按钮点击等各类触发事件以及可以自定义的动画过渡效果