Can you compile anything in C#?
If so.. Create a project with a form
Add a timer - 'timerSetKey' in my example.
Add a label - no real need to do this, mine is called 'labelResponse' but it's add some feed back.
Throw this in the form .cs file
Code:
Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace StopScreenSaver
{
public partial class FormStopScreenSaver : Form
{
public static int iCount=0;
[FlagsAttribute]
public enum EXECUTION_STATE : uint
{
ES_SYSTEM_REQUIRED = 0x00000001,
ES_DISPLAY_REQUIRED = 0x00000002,
// Legacy flag, should not be used.
// ES_USER_PRESENT = 0x00000004,
ES_AWAYMODE_REQUIRED = 0x00000040,
ES_CONTINUOUS = 0x80000000,
}
public static class SleepUtil
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
}
public void PreventSleep()
{
if (SleepUtil.SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS
| EXECUTION_STATE.ES_DISPLAY_REQUIRED
| EXECUTION_STATE.ES_SYSTEM_REQUIRED
| EXECUTION_STATE.ES_AWAYMODE_REQUIRED) == 0) //Away mode for Windows >= Vista
SleepUtil.SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS
| EXECUTION_STATE.ES_DISPLAY_REQUIRED
| EXECUTION_STATE.ES_SYSTEM_REQUIRED); //Windows < Vista, forget away mode
}
public static int iKeyPressed =0;
public FormStopScreenSaver()
{
InitializeComponent();
timerSetKey.Enabled = true;
}
private void timerSetKey_Tick(object sender, EventArgs e)
{
labelResponse.Text = string.Format("Count {0}",iCount.ToString());
labelResponse.Update();
PreventSleep();
iCount++;
}
}
}
StopScreenSaver is the name of my form.
Don't forget to set the timer to an interval relating to a second, set the tick event and ensure it is enabled by default else you will have to do it on form load or when the form initializes.
Add some nice Icons, and colours and away you go. Tested, proved and stolen!
Must admit I haven't tested it running as non admin, but I don't see an issue.
PM me if you want the project sent to you.