My code rotates a cube when Key.Q is held down. The animation looks smooth. If I press and hold Key.Q and then I press and hold Shift, Alt, Ctrl or CapsLock, the animation visibly stutters (holding Tab, Backspace or Enter does not). If I'm holding Key.Q and a modifier key and I release the modifier key the animation is smooth again. This is undesirable behavior and I want the animation to not be affected if these other keys are held.
Is this a background process being captured and if so is there an override for this behavior?
<Viewport3D Name="ViewportMain">
<Viewport3D.Camera>
<PerspectiveCamera x:Name="camMain" Position="6 5 4" LookDirection="-6 -5 -4">
</PerspectiveCamera>
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<AmbientLight Color="#ffffff" />
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D x:Name="MyModel">
<ModelVisual3D.Content>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D x:Name="meshMain"
Positions="0 0 0 1 0 0 0 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 1 1"
TriangleIndices="2 3 1 2 1 0 7 1 3 7 5 1 6 5 7 6 4 5 6 2 0 2 0 4 2 7 3 2 6 7 0 1 5 0 5 4">
</MeshGeometry3D>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial x:Name="matDiffuseMain">
<DiffuseMaterial.Brush>
<SolidColorBrush Color="Red"/>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
<ModelVisual3D.Transform>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D x:Name="rotate" Axis="0 2 0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
</ModelVisual3D.Transform>
</ModelVisual3D>
</Viewport3D>
Public WithEvents Timer1 As New System.Windows.Threading.DispatcherTimer()
Public ax3d As Media3D.AxisAngleRotation3D
Public myRotateTransform As Media3D.RotateTransform3D
Public isrotating As Boolean = False
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
ax3d = New Media3D.AxisAngleRotation3D(New Media3D.Vector3D(0, 2, 0), 1)
myRotateTransform = New Media3D.RotateTransform3D(ax3d)
MyModel.Transform = myRotateTransform
Timer1.IsEnabled = True
Timer1.Interval = TimeSpan.FromMilliseconds(1)
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
If isrotating Then
ax3d.Angle += 4
End If
End Sub
Private Sub Window_KeyDown(sender As Object, e As KeyEventArgs)
If e.IsRepeat Then
e.Handled = True
Return
End If
If e.Key = Key.Q Then
isrotating = True
e.Handled = True
End If
e.Handled = True
End Sub
Private Sub Window_KeyUp(sender As Object, e As KeyEventArgs)
If e.Key = Key.Q Then
isrotating = False
e.Handled = True
End If
End Sub
What I have tried:
I've tried other keys besides Q.
I've made several attempts to capture if modifier keys are held, i.e. "If e.Key = Key.LeftShift Or e.Key = Key.RightShift Then..." to capture the keydown and handle and exit the event but this hasn't made any noticeable difference.