extsmichalak
Topic Author
Posts: 6
Joined: 08 Feb 2021, 19:55

Key_GamepadAccept requires longer key press?

02 Aug 2021, 20:54

Hey!
Does `Key_GamepadAccept` require a longer key press? Tried on Switch or on PC with Xbox controller, seems like I need to press just a bit longer (~1 second, maybe less, but still longer then usual "key down"). What's interesting, if I change `Accept` to `Context2`, it's immediate.

Is it a problem of usage via `GamepadTrigger`? I saw in other threads that `Accept` requires button to be focused, but unsure if that's still true? It seems it still works, just differently :-)
 <Button
      Name="MyCustomButton"
      Focusable="False"
      Command="{Binding CommandName}">
      <i:Interaction.Triggers>
        <noesis:GamepadTrigger Button="Accept" FiredOn="ButtonDown">
          <i:InvokeCommandAction Command="{Binding CommandName}" />
        </noesis:GamepadTrigger>
      </i:Interaction.Triggers>
      <Button.Content>
         ...
      </Button.Content>
</Button>
Thanks,
Szymon
 
User avatar
sfernandez
Site Admin
Posts: 2329
Joined: 22 Dec 2011, 19:20

Re: Key_GamepadAccept requires longer key press?

03 Aug 2021, 19:41

This is happening because the Button logic is handling the KeyDown event for the Gamepad_Accept (as it will happen if pressing the Space key) to initiate the button press. On the KeyUp (for the default ClickMode=Release) it will fire the Click event. But if you don't release the Gamepad_Accept (or Space) it will start sending KeyDown events as key repeats. As those are not handled by the Button, they are received by the GamepadTrigger that will execute the corresponding actions.

Anyway, looking at your xaml I have one question. Why do you need the GamepadTrigger if by default the Button will execute the bound Command on Click (pressing the Accept button will just raise the Click event)?
 
extsmichalak
Topic Author
Posts: 6
Joined: 08 Feb 2021, 19:55

Re: Key_GamepadAccept requires longer key press?

03 Aug 2021, 21:03

Thanks for quick reply!
I just tried removing GamepadTrigger and now it doesn't react on Gamepad_Accept at all (still works on click though). Is this a problem of the button not being Focusable?
Basically we need to handle pressing Accept to move forward without the need to focus on that button.
 
User avatar
sfernandez
Site Admin
Posts: 2329
Joined: 22 Dec 2011, 19:20

Re: Key_GamepadAccept requires longer key press?

03 Aug 2021, 21:25

Oh, didn't notice the Focusable=False on the Button. So if that button is not focused, what control has focus? another button?
 
extsmichalak
Topic Author
Posts: 6
Joined: 08 Feb 2021, 19:55

Re: Key_GamepadAccept requires longer key press?

04 Aug 2021, 16:17

Yes, another button is focused. Also probably worth noting that the button that handles Accept key press has following content:
<Button.Content>
        <TextBlock
          ...
          Focusable="True"
          Text="..." />
</Button.Content>
 
User avatar
sfernandez
Site Admin
Posts: 2329
Joined: 22 Dec 2011, 19:20

Re: Key_GamepadAccept requires longer key press?

04 Aug 2021, 19:48

If a Button has the focus, pressing the Gamepad_Accept will always fire the Click event on that button (without any GamepadTrigger), it will be the same as clicking the focused button.

I think what you are trying to do is if no Button has the focus and user presses the Gamepad_Accept, fire the Command anyway. I would define the trigger on a parent panel to avoid confusion (when GamepadTrigger.ActiveOnFocus is not set, the trigger will always be listening if the keydown/up reaches the root), and set the FiredOn=ButtonUp, so only a completed press/release fires the command action.
<StackPanel>
  <i:Interaction.Triggers>
    <noesis:GamepadTrigger Button="Accept" FiredOn="ButtonUp">
      <i:InvokeCommandAction Command="{Binding OkCommand}"/>
    </noesis:GamepadTrigger>
  <i:Interaction.Triggers>
  
  <Button Content="OK" Command="{Binding OkCommand}"/>
  <Button Content="Back" Command="{Binding BackCommand}"/>
</StackPanel>
 
extsmichalak
Topic Author
Posts: 6
Joined: 08 Feb 2021, 19:55

Re: Key_GamepadAccept requires longer key press?

06 Aug 2021, 16:05

Tried, exactly the same behavior... what's interesting `FiredOn="ButtonUp"` didn't work at all, had to revert to `FiredOn="ButtonDown"`
 
User avatar
sfernandez
Site Admin
Posts: 2329
Joined: 22 Dec 2011, 19:20

Re: Key_GamepadAccept requires longer key press?

06 Aug 2021, 19:42

Tried, exactly the same behavior... what's interesting `FiredOn="ButtonUp"` didn't work at all, had to revert to `FiredOn="ButtonDown"`
I don't understand... I just tried previous xaml within our XamlPlayer, and when I don't have the focus in any of the two buttons or their content, the GamepadTrigger is correctly fired.

You said that the Button handling the accept key had a focusable TextBlock, how are you setting the focus on that element? Are you pressing the accept key when the focus is in that TextBlock element? because then the Button will handle the KeyDown event and won't reach the root as I mentioned before (so GamepadTrigger won't fire).
 
User avatar
sfernandez
Site Admin
Posts: 2329
Joined: 22 Dec 2011, 19:20

Re: Key_GamepadAccept requires longer key press?

06 Aug 2021, 19:42

Tried, exactly the same behavior... what's interesting `FiredOn="ButtonUp"` didn't work at all, had to revert to `FiredOn="ButtonDown"`
I don't understand... I just tried previous xaml within our XamlPlayer, and when I don't have the focus in any of the two buttons or their content, the GamepadTrigger is correctly fired.

You said that the Button handling the accept key had a focusable TextBlock, how are you setting the focus on that element? Are you pressing the accept key when the focus is in that TextBlock element? It should work anyway, like in the following xaml:
<Grid 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
  xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
  xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions">

  <Rectangle x:Name="rect" Width="400" Height="300" Fill="Red"/>
  
  <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
    <i:Interaction.Triggers>
      <noesis:GamepadTrigger Button="Accept" FiredOn="ButtonUp">
        <i:InvokeCommandAction Command="{Binding OkCommand}"/>
        <ei:ChangePropertyAction TargetName="rect" PropertyName="Fill" Value="Green"/>
      </noesis:GamepadTrigger>
    </i:Interaction.Triggers>
    
    <Button Command="{Binding OkCommand}" Margin="0,10" Focusable="False">
      <ContentControl Focusable="True" Content="OK"/>
    </Button>
    <Button Content="Back" Command="{Binding BackCommand}"/>
  </StackPanel>

</Grid>

Who is online

Users browsing this forum: Google [Bot], sfernandez and 4 guests