Announcement

Collapse
No announcement yet.

Control widget with key press?

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

    Control widget with key press?

    Hi,

    I'm sure this should be really simple, but I can't figure out exactly how it's done.

    I have a UI I have built in a Widget Blueprint. I want to be able to make changes to it with key presses, for example pressing Space starts/stops something on the UI.

    But in the Widget Blueprint itself, I can't get a key press event. It seems one can only get those types of events inside a Player Controller Blueprint, or am I mistaken?

    So I assume I need the key press to fire some kind of event in the Player Controller, which the Widget is listening for?

    Would love some help to figure this out!

    Thanks,LS

    #2
    Hi localstarlight,

    You need to use "Set Keyboard Focus" after "Add to Viewport"




    Then go to your Widget Blueprint and override the function "On Key Down" or "On Key Up", whatever you want.




    By last, in the new function you can detect any key you want.




    I really don't know all the differences about return Handled or Unhandled, but I know that Handled block another Inputs that are in another blueprint, Unhandled not.
    Last edited by KlSKE; 09-24-2015, 08:03 PM.

    Comment


      #3
      Thanks for your reply (ages ago!) – I still haven't managed to make this work.

      I've tried what you suggested (I think). Here is my Level Blueprint:

      Click image for larger version

Name:	Screen Shot 2016-05-12 at 12.30.26.png
Views:	1
Size:	88.7 KB
ID:	1106297

      And here's my Widget Blueprint:

      Click image for larger version

Name:	Screen Shot 2016-05-12 at 12.30.48.png
Views:	1
Size:	116.2 KB
ID:	1106298

      When I press 'A' it doesn't do anything – it doesn't go down either fork of the branch, so it's clearly not coming through.

      What am I doing wrong?!

      Comment


        #4
        So I realised I hadn't done what you'd suggested. For some reason the 'Set Keyboard Focus' node wasn't showing up for me until I turned off 'Context Sensitive'.

        So now it looks like this:

        Click image for larger version

Name:	Screen Shot 2016-05-12 at 13.29.27.png
Views:	1
Size:	71.5 KB
ID:	1106301

        But it still doesn't do anything when I press the 'A' key...

        Comment


          #5
          Not 100% certain, but if that's in the Level Blueprint, then you will probably need to tell who the Owning Player is when creating the widget.

          Comment


            #6
            I have tried adding that, so now Level Blueprint looks like this:

            Click image for larger version

Name:	Screen Shot 2016-05-12 at 18.51.23.png
Views:	1
Size:	90.7 KB
ID:	1106315

            But still doesn't work...

            Comment


              #7
              So, does it actually draw the widget to the screen, or is it just not accepting the override input?

              Comment


                #8
                The widget draws fine, just not accepting any input. Is there another step/setting needed to make this work?

                Comment


                  #9
                  I can't believe this is such an unusual thing to want to do, and yet nothing I try seems to work.

                  Does anyone know of a tutorial that goes through such a thing? Or does anyone have a working example of affecting a widget with the keyboard that I could look at?

                  Comment


                    #10
                    https://answers.unrealengine.com/que...serwidget.html

                    this works, however you will need to use event tick for all the widget that needs input, and you need to define it for each key.
                    i am in the same page as you trying to enable the input for the widget, even worst since i want to swipe my widget.

                    Comment


                      #11
                      There's one piece missing here that I needed to make this work. Maybe it's new since this was posted. In the widget, after event construct, you need to set Is Focusable to true. This allows the Set Keyboard Focus node to work. Then the key down event overrides also work.

                      Comment


                        #12
                        Make an input action for your key press.

                        Comment


                          #13
                          From inside the Widget Blueprint:
                          EventOnInitialize->SetIsFocusable
                          EventOnMouseEnter->SetKeyboardFocus
                          EventOnMouseLeave->SetFocusToGameViewport

                          Works for me, thanks guys. Unreal 4.23
                          NodePrefabs | PluginBuilder | NotificationBackbone | WidgetBox | RuntimeMeshImportExport | DebugWidget | SteamWorkshopAccessor

                          Comment

                          Working...
                          X