1212#endregion
1313
1414using System ;
15+ using System . Runtime . InteropServices ;
1516using System . Windows . Forms ;
1617
1718using 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}
0 commit comments