I am writing a WPF application for a kiosk. The kiosk will go unused for extended periods so I want to create a "screen saver"-like feature where I can show some promotional slides that are then interrupted when a person touches the screen and starts the application. How can I go about doing this?
I dont know if there is something nativ, but you can make it.
Dont forget to add a timer to launch it.
By the way, I just google your question and find a lot of sample :
It sounds like a screensaver would do what you want (like others have said) but you asked for a screen-saver like feature. I'm assuming that you don't need help making a window and showing the slideshow. Probably more like when to show it.
I had written an app (WPF) for a client several years ago (4+?) that needed to track when a user was and was not actively doing something in the application. Google (searches - not Google itself) and I came up with the following. I hope you find it useful. To use it:
AppActivityTimer activityTimer; // In my app, this is a member variable of the main window
activityTimer = new AppActivityTimer(
30*1000, // plain timer, going off every 30 secs - not useful for your question
5*60*1000, // how long to wait for no activity before firing OnInactive event - 5 minutes
true); // Does mouse movement count as activity?
activityTimer.OnInactive += new EventHandler(activityTimer_OnInactive);
activityTimer.OnActive += new PreProcessInputEventHandler(activityTimer_OnActive);
activityTimer.OnTimePassed += new EventHandler(activityTimer_OnTimePassed);
void activityTimer_OnTimePassed(object sender, EventArgs e)
{
// Regular timer went off
}
void activityTimer_OnActive(object sender, PreProcessInputEventArgs e)
{
// Activity detected (key press, mouse move, etc) - close your slide show, if it is open
}
void activityTimer_OnInactive(object sender, EventArgs e)
{
// App is inactive - activate your slide show - new full screen window or whatever
// FYI - The last input was at:
// DateTime idleStartTime = DateTime.Now.Subtract(activityTimer.InactivityThreshold);
}
And the AppActivityTimer class itself:
public class AppActivityTimer
{
#region Events - OnActive, OnInactive, OnTimePassed
public event System.Windows.Input.PreProcessInputEventHandler OnActive;
public event EventHandler OnInactive;
public event EventHandler OnTimePassed;
#endregion
#region TimePassed
private TimeSpan _timePassed;
private DispatcherTimer _timePassedTimer;
#endregion
#region Inactivity
public TimeSpan InactivityThreshold { get; private set; }
private DispatcherTimer _inactivityTimer;
private Point _inactiveMousePosition = new Point(0, 0);
private bool _MonitorMousePosition;
#endregion
#region Constructor
/// <summary>
/// Timers for activity, inactivity and time passed.
/// </summary>
/// <param name="timePassedInMS">Time in milliseconds to fire the OnTimePassed event.</param>
/// <param name="IdleTimeInMS">Time in milliseconds to be idle before firing the OnInactivity event.</param>
/// <param name="WillMonitorMousePosition">Does a change in mouse position count as activity?</param>
public AppActivityTimer(int timePassedInMS, int IdleTimeInMS, bool WillMonitorMousePosition)
{
_MonitorMousePosition = WillMonitorMousePosition;
System.Windows.Input.InputManager.Current.PreProcessInput += new System.Windows.Input.PreProcessInputEventHandler(OnActivity);
// Time Passed Timer
_timePassedTimer = new DispatcherTimer();
_timePassed = TimeSpan.FromMilliseconds(timePassedInMS);
// Start the time passed timer
_timePassedTimer.Tick += new EventHandler(OnTimePassedHandler);
_timePassedTimer.Interval = _timePassed;
_timePassedTimer.IsEnabled = true;
// Inactivity Timer
_inactivityTimer = new DispatcherTimer();
InactivityThreshold = TimeSpan.FromMilliseconds(IdleTimeInMS);
// Start the inactivity timer
_inactivityTimer.Tick += new EventHandler(OnInactivity);
_inactivityTimer.Interval = InactivityThreshold;
_inactivityTimer.IsEnabled = true;
}
#endregion
#region OnActivity
void OnActivity(object sender, System.Windows.Input.PreProcessInputEventArgs e)
{
System.Windows.Input.InputEventArgs inputEventArgs = e.StagingItem.Input;
if (inputEventArgs is System.Windows.Input.MouseEventArgs || inputEventArgs is System.Windows.Input.KeyboardEventArgs)
{
if (inputEventArgs is System.Windows.Input.MouseEventArgs)
{
System.Windows.Input.MouseEventArgs mea = inputEventArgs as System.Windows.Input.MouseEventArgs;
// no button is pressed and the position is still the same as the application became inactive
if (mea.LeftButton == System.Windows.Input.MouseButtonState.Released &&
mea.RightButton == System.Windows.Input.MouseButtonState.Released &&
mea.MiddleButton == System.Windows.Input.MouseButtonState.Released &&
mea.XButton1 == System.Windows.Input.MouseButtonState.Released &&
mea.XButton2 == System.Windows.Input.MouseButtonState.Released &&
(_MonitorMousePosition == false ||
(_MonitorMousePosition == true && _inactiveMousePosition == mea.GetPosition(Application.Current.MainWindow)))
)
return;
}
// Reset idle timer
_inactivityTimer.IsEnabled = false;
_inactivityTimer.IsEnabled = true;
_inactivityTimer.Stop();
_inactivityTimer.Start();
if (OnActive != null)
OnActive(sender, e);
}
}
#endregion
#region OnInactivity
void OnInactivity(object sender, EventArgs e)
{
// Fires when app has gone idle
_inactiveMousePosition = System.Windows.Input.Mouse.GetPosition(Application.Current.MainWindow);
_inactivityTimer.Stop();
if (OnInactive != null)
OnInactive(sender, e);
}
#endregion
#region OnTimePassedHandler
void OnTimePassedHandler(object sender, EventArgs e)
{
if (OnTimePassed != null)
OnTimePassed(sender, e);
}
#endregion
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With