Skip to content

Commit 5fe2473

Browse files
committed
Add ability to keep screen on and not sleep
1 parent 7455095 commit 5fe2473

File tree

4 files changed

+72
-29
lines changed

4 files changed

+72
-29
lines changed

MainForm.Designer.cs

Lines changed: 31 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MainForm.cs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#endregion
1313

1414
using System;
15+
using System.Runtime.InteropServices;
1516
using System.Windows.Forms;
1617

1718
using Microsoft.Win32;
@@ -21,7 +22,6 @@ namespace ArkaneSystems.MouseJiggle
2122
public partial class MainForm : Form
2223
{
2324
private const int MOUSEMOVE = 8;
24-
2525
protected bool zig = true;
2626

2727
public MainForm()
@@ -38,8 +38,6 @@ private void jiggleTimer_Tick(object sender, EventArgs e)
3838
}
3939
else // zag
4040
{
41-
// I really don't know why this needs to be less to stay in the same
42-
// place; if I was likely to use it again, then I'd worry.
4341
Jiggler.Jiggle(-4, -4);
4442
this.jiggleTimer.Interval = Program.JiggleInterval * 60 * 1000;
4543
}
@@ -52,10 +50,11 @@ private void updateJiggleTimer()
5250
this.jiggleTimer.Interval = Program.JiggleInterval * 60 * 1000;
5351
}
5452

55-
private void cbEnabled_CheckedChanged(object sender, EventArgs e)
53+
private void cbEnabledJiggle_CheckedChanged(object sender, EventArgs e)
5654
{
5755
updateJiggleTimer();
58-
this.jiggleTimer.Enabled = this.cbEnabled.Checked;
56+
this.jiggleTimer.Enabled = this.cbEnableJiggle.Checked;
57+
this.intervalUpDown.Enabled = this.cbEnableJiggle.Checked;
5958
}
6059

6160
private void cmdAbout_Click(object sender, EventArgs e)
@@ -67,7 +66,10 @@ private void cmdAbout_Click(object sender, EventArgs e)
6766
private void MainForm_Load(object sender, EventArgs e)
6867
{
6968
if (Program.StartJiggling)
70-
this.cbEnabled.Checked = true;
69+
this.cbEnableJiggle.Checked = true;
70+
71+
if (Program.StartScreenOn)
72+
this.cbKeepScreenOn.Checked = true;
7173

7274
if (Program.StartMinimized)
7375
this.cmdToTray_Click(this, null);
@@ -104,5 +106,27 @@ private void intervalUpDown_ValueChanged(object sender, EventArgs e)
104106
Program.JiggleInterval = (int) ((NumericUpDown)sender).Value;
105107
updateJiggleTimer();
106108
}
109+
110+
private void cbKeepScreenOn_CheckedChanged(object sender, EventArgs e)
111+
{
112+
if (this.cbKeepScreenOn.Checked)
113+
NativeMethods.SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_SYSTEM_REQUIRED);
114+
else
115+
NativeMethods.SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
116+
}
117+
}
118+
119+
public enum EXECUTION_STATE : uint
120+
{
121+
ES_AWAYMODE_REQUIRED = 0x00000040,
122+
ES_CONTINUOUS = 0x80000000,
123+
ES_DISPLAY_REQUIRED = 0x00000002,
124+
ES_SYSTEM_REQUIRED = 0x00000001
125+
}
126+
127+
internal class NativeMethods
128+
{
129+
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
130+
public static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
107131
}
108132
}

Program.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ internal static class Program
2121
{
2222
public static bool StartJiggling = false;
2323
public static bool StartMinimized = false;
24+
public static bool StartScreenOn = false;
2425
public static int JiggleInterval = 1; // Minutes
2526

2627
/// <summary>
@@ -42,6 +43,10 @@ private static void Main (string[] args)
4243
(System.String.Compare(arg.ToUpperInvariant(), "-J", System.StringComparison.Ordinal) == 0))
4344
StartJiggling = true;
4445

46+
if ((System.String.Compare(arg.ToUpperInvariant(), "--SCREEN", System.StringComparison.Ordinal) == 0) ||
47+
(System.String.Compare(arg.ToUpperInvariant(), "-S", System.StringComparison.Ordinal) == 0))
48+
StartScreenOn = true;
49+
4550
if (
4651
(System.String.Compare(arg.ToUpperInvariant(), "--MINIMIZED", System.StringComparison.Ordinal) == 0) ||
4752
(System.String.Compare(arg.ToUpperInvariant(), "-M", System.StringComparison.Ordinal) == 0))

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ computer normally even with jiggling enabled.
1919

2020
To minimize Mouse Jiggler to the system tray, click the button marked with a green, down-pointing arrow.
2121

22-
If you want to start the Mouse Jiggler with jiggling already enabled, run the MouseJiggle.exe with either the
23-
-j or --jiggle command-line switch.
22+
Command Line Switches
23+
=====================
2424

25-
The "-i [minutes]" / "--interval [minutes]" (ie, -i 10) command-line argument allows you to set the number of minutes between jiggles.
26-
27-
(Added in 1.5+): The "-m" / "--minimized" command-like switch tells MouseJiggler to start already minimized.
28-
29-
That's it. Enjoy!
25+
* --jiggle | -j ... start jiggling on load
26+
* --interval [min] | -i [min] ... set minutes between jiggles
27+
* --minimized | -m ... start minimized
28+
* --screen | -s ... start with screen on enabled
3029

3130
Features That Will Not Be Implemented
3231
=====================================

0 commit comments

Comments
 (0)