Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I shake a users desktop using WPF?

Tags:

I'm writing an application for personal use that will track how often I reach for the mouse, and will keep a counter of how long I've gone mouseless. When I use the mouse, I would like it to shake my desktop workspace for a second as a negative reinforcement action.

The application is going to be called WristSlap and will be on github as soon as I have a version 0.1 ready.

like image 549
Scott Muc Avatar asked Mar 04 '10 20:03

Scott Muc


2 Answers

Danny is onto something with the transparent window idea. But it doesn't have to be transparent. You would have to accept some certain limitations though.

You would want to grab a screen shot of the desktop and apply it to a full screen WPF window. (Check out my blog for a handy FullScreenBehavior for WPF Window). Then you would just apply some epilepsy-inducing animation to a translate layout transform on the root element. This would give the effect of shaking. At the end the window could just close.

Since during the animation the coordinates of everything will be all over the place, you probably don't want to be bothered with trying to translate mouse clicks on the moving desktop to the underlying control. If the animation is short enough it won't matter because you won't have time to try to click anything while it is shaking.

For more realism you could look into using the DWM (Desktop Window Manager) to project a "live" view of the desktop but that's probably not worth it especially if you keep the animation very short.

I almost want to try this myself for fun.

I came up with this using a static image for now. It's ok but it could be improved.

<Image Source="Slide1.png" Stretch="UniformToFill">

<Image.Effect>
  <BlurEffect Radius="5" />
</Image.Effect>

<Image.RenderTransform>
  <TranslateTransform Y="0" X="0"/>
</Image.RenderTransform>

<Image.Triggers>
  <EventTrigger RoutedEvent="FrameworkElement.Loaded">
    <BeginStoryboard>
      <Storyboard RepeatBehavior="00:00:01" SpeedRatio="15">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)">
          <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="-10"/>
          <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0"/>
          <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="10"/>
          <SplineDoubleKeyFrame KeyTime="00:00:00.7000000" Value="0"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)">
          <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="-10"/>
          <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="-10"/>
          <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="10"/>
          <SplineDoubleKeyFrame KeyTime="00:00:00.7000000" Value="10"/>
          <SplineDoubleKeyFrame KeyTime="00:00:00.9000000" Value="0"/>
        </DoubleAnimationUsingKeyFrames>
      </Storyboard>
    </BeginStoryboard>
  </EventTrigger>
</Image.Triggers>

</Image>
like image 57
Josh Avatar answered Oct 11 '22 16:10

Josh


You could create a transparent window with a changing twirl shader effect.

I'm not sure that will solve your addiction to computers though.

like image 40
Danny Varod Avatar answered Oct 11 '22 15:10

Danny Varod