- extsmichalak
- Posts: 21
- Joined:
Key_GamepadAccept requires longer key press?
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 :-)
Thanks,
Szymon
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 :-)
Code: Select all
<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>
Szymon
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Key_GamepadAccept requires longer key press?
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)?
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
- Posts: 21
- Joined:
Re: Key_GamepadAccept requires longer key press?
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.
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.
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Key_GamepadAccept requires longer key press?
Oh, didn't notice the Focusable=False on the Button. So if that button is not focused, what control has focus? another button?
- extsmichalak
- Posts: 21
- Joined:
Re: Key_GamepadAccept requires longer key press?
Yes, another button is focused. Also probably worth noting that the button that handles Accept key press has following content:
Code: Select all
<Button.Content>
<TextBlock
...
Focusable="True"
Text="..." />
</Button.Content>
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Key_GamepadAccept requires longer key press?
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.
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.
Code: Select all
<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
- Posts: 21
- Joined:
Re: Key_GamepadAccept requires longer key press?
Tried, exactly the same behavior... what's interesting `FiredOn="ButtonUp"` didn't work at all, had to revert to `FiredOn="ButtonDown"`
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Key_GamepadAccept requires longer key press?
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.Tried, exactly the same behavior... what's interesting `FiredOn="ButtonUp"` didn't work at all, had to revert to `FiredOn="ButtonDown"`
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).
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Key_GamepadAccept requires longer key press?
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.Tried, exactly the same behavior... what's interesting `FiredOn="ButtonUp"` didn't work at all, had to revert to `FiredOn="ButtonDown"`
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:
Code: Select all
<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: Semrush [Bot] and 81 guests