Skip to content

Commit

Permalink
Add ability to keep screen on and not sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
droidmonkey committed May 10, 2018
1 parent 7455095 commit 5fe2473
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 29 deletions.
47 changes: 31 additions & 16 deletions MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 30 additions & 6 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#endregion

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

using Microsoft.Win32;
Expand All @@ -21,7 +22,6 @@ namespace ArkaneSystems.MouseJiggle
public partial class MainForm : Form
{
private const int MOUSEMOVE = 8;

protected bool zig = true;

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

private void cbEnabled_CheckedChanged(object sender, EventArgs e)
private void cbEnabledJiggle_CheckedChanged(object sender, EventArgs e)
{
updateJiggleTimer();
this.jiggleTimer.Enabled = this.cbEnabled.Checked;
this.jiggleTimer.Enabled = this.cbEnableJiggle.Checked;
this.intervalUpDown.Enabled = this.cbEnableJiggle.Checked;
}

private void cmdAbout_Click(object sender, EventArgs e)
Expand All @@ -67,7 +66,10 @@ private void cmdAbout_Click(object sender, EventArgs e)
private void MainForm_Load(object sender, EventArgs e)
{
if (Program.StartJiggling)
this.cbEnabled.Checked = true;
this.cbEnableJiggle.Checked = true;

if (Program.StartScreenOn)
this.cbKeepScreenOn.Checked = true;

if (Program.StartMinimized)
this.cmdToTray_Click(this, null);
Expand Down Expand Up @@ -104,5 +106,27 @@ private void intervalUpDown_ValueChanged(object sender, EventArgs e)
Program.JiggleInterval = (int) ((NumericUpDown)sender).Value;
updateJiggleTimer();
}

private void cbKeepScreenOn_CheckedChanged(object sender, EventArgs e)
{
if (this.cbKeepScreenOn.Checked)
NativeMethods.SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_SYSTEM_REQUIRED);
else
NativeMethods.SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
}
}

public enum EXECUTION_STATE : uint
{
ES_AWAYMODE_REQUIRED = 0x00000040,
ES_CONTINUOUS = 0x80000000,
ES_DISPLAY_REQUIRED = 0x00000002,
ES_SYSTEM_REQUIRED = 0x00000001
}

internal class NativeMethods
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
}
}
5 changes: 5 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal static class Program
{
public static bool StartJiggling = false;
public static bool StartMinimized = false;
public static bool StartScreenOn = false;
public static int JiggleInterval = 1; // Minutes

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

if ((System.String.Compare(arg.ToUpperInvariant(), "--SCREEN", System.StringComparison.Ordinal) == 0) ||
(System.String.Compare(arg.ToUpperInvariant(), "-S", System.StringComparison.Ordinal) == 0))
StartScreenOn = true;

if (
(System.String.Compare(arg.ToUpperInvariant(), "--MINIMIZED", System.StringComparison.Ordinal) == 0) ||
(System.String.Compare(arg.ToUpperInvariant(), "-M", System.StringComparison.Ordinal) == 0))
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ computer normally even with jiggling enabled.

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

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

The "-i [minutes]" / "--interval [minutes]" (ie, -i 10) command-line argument allows you to set the number of minutes between jiggles.

(Added in 1.5+): The "-m" / "--minimized" command-like switch tells MouseJiggler to start already minimized.

That's it. Enjoy!
* --jiggle | -j ... start jiggling on load
* --interval [min] | -i [min] ... set minutes between jiggles
* --minimized | -m ... start minimized
* --screen | -s ... start with screen on enabled

Features That Will Not Be Implemented
=====================================
Expand Down

0 comments on commit 5fe2473

Please sign in to comment.