-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
142 lines (125 loc) · 4.58 KB
/
MainWindow.xaml.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
133
134
135
136
137
138
139
140
141
142
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MahApps.Metro.Controls;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Application = System.Windows.Forms.Application;
namespace afkCheck0r
{
public partial class MainWindow : MetroWindow
{
[DllImport("user32")]
public static extern bool ExitWindowsEx(uint uFlags, uint dwReason);
[DllImport("user32")]
public static extern void LockWorkStation();
public Boolean running = false;
public static System.Timers.Timer aTimer;
System.Windows.Threading.DispatcherTimer dispatcherTimer = null;
//public event TextChangedEventHandler TextChanged;
public static int i = 60;
public static String test = "";
System.DateTime start = System.DateTime.Now;
System.DateTime now = System.DateTime.Now;
System.TimeSpan duration;
DateTime final;
public Point Location { get; private set; }
public MainWindow()
{
InitializeComponent();
// TextChanged += new TextChangedEventHandler(counterDisplay_TextChanged);
var desktopWorkingArea = System.Windows.SystemParameters.WorkArea;
this.Left = desktopWorkingArea.Right - this.Width;
this.Top = desktopWorkingArea.Bottom - this.Height;
if (!running)
{
lblTime.Content = i + " s";
lblTime.FontSize = 54;
start = System.DateTime.Now;
duration = new System.TimeSpan(0, 0, 1, 0);
final = System.DateTime.Now.AddSeconds(10);
dispatcherTimer = null;
dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += dispatcherTimer_Tick;
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
running = true;
return;
}
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
test = i.ToString();
lblTime.Content = i + " s";
i--;
if(running)
{
if (System.DateTime.Now >= final)
{
doStuff();
System.Windows.Application.Current.Shutdown();
}
}
}
private static void doStuff()
{
Application.SetSuspendState(PowerState.Hibernate, true, true);
// Shutdown: Process.Start("shutdown", "/s /t 0");
// Hibernate: Application.SetSuspendState(PowerState.Hibernate, true, true);
// Logscreen: LockWorkStation();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (!running)
{
this.startStopBtn.Content = "STOP";
final = System.DateTime.Now.AddMinutes(1);
dispatcherTimer = null;
dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += dispatcherTimer_Tick;
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
running = true;
return;
}
if(running)
{
this.startStopBtn.Content = "START";
final = DateTime.Now.AddHours(2);
dispatcherTimer.Stop();
dispatcherTimer = null;
i = 60;
lblTime.Content = i + " s";
running = false;
}
}
private void MetroWindow_KeyDown_1(object sender, System.Windows.Input.KeyEventArgs e)
{
if (running)
{
System.Windows.Application.Current.Shutdown();
}
}
private void startStopBtn_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
this.startStopBtn.Background = Brushes.DarkGray;
}
private void startStopBtn_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
this.startStopBtn.Background = Brushes.LightGray;
}
}
}