learned/learning/to learn RSS 2.0
# Thursday, 12 November 2009

This program prevents your system from getting locked even if it is left idle for time greater than your screen saver time. It basically presses ‘down’ arrow key every minute.

 

Create a Windows Forms Application and add a timer to the form.

 

public Form1()

{

    InitializeComponent();

    StartAction();

}

 

private void StartAction()

{

    // the timer is started and the form is minimized

    // set the timer interval as per your needs. I have set it to be 60000 milliseconds = 1 min

    timer_keypress.Enabled = true;

    this.WindowState = FormWindowState.Minimized;

    this.ShowInTaskbar = false;

}

 

 

To add the application to your system tray when minimized, add a notify icon from your toolbox to the forms and set properties appropriately. I chose an icon and changed the text property. By default this form will be in minimized state, as I have added code to do so in my StartAction function.

 

Add context menu from your toolbox to show menu when the system tray icon is right clicked. Right click contextMenuStrip and choose Edit items to add your menu items. Double click on the menu item to add a handler. I’ve added ‘Exit’ menu. Set your notify icon’s contextmenustrip property.

 

private void exitToolStripMenuItem_Click(object sender, EventArgs e)

{

    StopAction();

}

 

private void StopAction()

{

    // the timer is stopped and the form is closed  

    timer_keypress.Enabled = false;

    this.Close();

}

 

// this event will be triggered every minute

private void timer_keypress_Tick(object sender, EventArgs e)

{

    SendKeys.SendWait("{DOWN}");

}

 

There are many ways to do this, I found this one to be easy.


Here is the fileKeyPress.exe (889 KB)
Thursday, 12 November 2009 22:52:51 (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET
Navigation
Archive
<2009 November>
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2017
Gokulnath
Sign In
Statistics
Total Posts: 41
This Year: 0
This Month: 0
This Week: 0
Comments: 47
Themes
Pick a theme:
All Content © 2017, Gokulnath
DasBlog theme 'Business' created by Christoph De Baene (delarou)