Page 1 of 1

VGUI Joypad Input in SDK 2013

PostPosted: Fri Dec 06, 2013 10:44 am
by SM Sith Lord
I need my VGUI panel to capture the left analog stick from the joypad. In 2007 SDK, I was able to do this using the following code:
Code: Select all
void CHDViewInput::OnKeyCodePressed(KeyCode code)
{
   if( IsJoystickAxisCode(code) ) {
      if( code == KEY_XSTICK1_UP )
         m_bMoveUp = true;
      else if( code == KEY_XSTICK1_DOWN )
         m_bMoveDown = true;
      else if( code == KEY_XSTICK1_LEFT )
         m_bMoveLeft = true;
      else if( code == KEY_XSTICK1_RIGHT )
         m_bMoveRight = true;

      return;
   }
}


In 2007, this code would capture the left analog stick and ignore all other joypad input. However, in 2013 SDK this does nothing. This is probably due to the improved controller support in the new SDK. Now you can control the main menu with the dpad on your joystick; you couldn't do that back in 2007.

Does anybody know how to make my VGUI panel capture the left analog stick of the joypad in 2013?

Re: VGUI Joypad Input in SDK 2013

PostPosted: Fri Dec 06, 2013 5:56 pm
by zombie@computer
No idea but maybe code is a bitfield now? I mean you'd need to check if (code & KEY_XSTICK1_UP) instead of == ?

Re: VGUI Joypad Input in SDK 2013

PostPosted: Sat Dec 07, 2013 2:06 pm
by SM Sith Lord
The problem is that no code what so ever gets sent when I move the joystick while in a VGUI menu now. :( The method isn't even called anymore.

Re: VGUI Joypad Input in SDK 2013

PostPosted: Sat Dec 07, 2013 2:09 pm
by zombie@computer
Ah. Thats a problem then :|

Re: VGUI Joypad Input in SDK 2013

PostPosted: Sun Dec 08, 2013 5:52 pm
by Garrador
Is
Code: Select all
Panel::OnKeyCodeTyped(KeyCode keycode)
called when you move the stick??

Browsed through the source code on github, and in that function this was commented out:

Code: Select all
// legacy handling - need to re-enable for older apps?
                /*
                if ( code == KEY_XSTICK1_RIGHT || code == KEY_XBUTTON_RIGHT )
                {
                RequestFocusNext();
                return;
                }
                else if ( code == KEY_XSTICK1_LEFT || code == KEY_XBUTTON_LEFT )
                {
                RequestFocusPrev();
                return;
                }
                */


Might this affect it? Perhaps there is some problem with focusing input on the panel whilst using a joypad..

Re: VGUI Joypad Input in SDK 2013

PostPosted: Mon Dec 09, 2013 12:48 pm
by SM Sith Lord
I haven't tried monitoring higher up in the inheritance hierarchy yet, I'll look there next, thank you. I know that the OnKeyCodePressed doesn't get called from my panel, which inherits from the Panel class, but I actually haven't tried tapping into the OnKeyTyped message at all yet.

The code you found there seems like they were thinking about letting the analog stick change your menu selection, however only the d-pad does that now. RequestFocusNext() must be the function to step through the different buttons/elements you have in your panel. Very helpful. I'll post here if I figure anything new out.