forked from arkane-systems/mousejiggler
-
Notifications
You must be signed in to change notification settings - Fork 3
/
MainForm.cs
132 lines (107 loc) · 3.54 KB
/
MainForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#region header
// MouseJiggle - MainForm.cs
//
// Alistair J. R. Young
// Arkane Systems
//
// Copyright Arkane Systems 2012-2013.
//
// Created: 2013-08-24 12:41 PM
#endregion
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.Win32;
namespace ArkaneSystems.MouseJiggle
{
public partial class MainForm : Form
{
private const int MOUSEMOVE = 8;
protected bool zig = true;
public MainForm()
{
this.InitializeComponent();
}
private void jiggleTimer_Tick(object sender, EventArgs e)
{
if (this.zig)
{
Jiggler.Jiggle(4, 4);
this.jiggleTimer.Interval = 500;
}
else // zag
{
Jiggler.Jiggle(-4, -4);
this.jiggleTimer.Interval = Program.JiggleInterval * 60 * 1000;
}
this.zig = !this.zig;
}
private void updateJiggleTimer()
{
this.jiggleTimer.Interval = Program.JiggleInterval * 60 * 1000;
}
private void cbEnabledJiggle_CheckedChanged(object sender, EventArgs e)
{
updateJiggleTimer();
this.jiggleTimer.Enabled = this.cbEnableJiggle.Checked;
this.intervalUpDown.Enabled = this.cbEnableJiggle.Checked;
}
private void cmdAbout_Click(object sender, EventArgs e)
{
using (var a = new AboutBox())
a.ShowDialog();
}
private void MainForm_Load(object sender, EventArgs e)
{
if (Program.StartJiggling)
this.cbEnableJiggle.Checked = true;
if (Program.StartScreenOn)
this.cbKeepScreenOn.Checked = true;
if (Program.StartMinimized)
this.cmdToTray_Click(this, null);
this.intervalUpDown.Value = Program.JiggleInterval;
}
private void cmdToTray_Click (object sender, EventArgs e)
{
// minimize to tray
this.Visible = false;
// remove from taskbar
this.ShowInTaskbar = false;
// show tray icon
this.nifMin.Visible = true;
}
private void nifMin_DoubleClick(object sender, EventArgs e)
{
// restore the window
this.Visible = true;
// replace in taskbar
this.ShowInTaskbar = true;
// hide tray icon
this.nifMin.Visible = false;
}
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);
}
}