forked from Half1900/AlphaClicker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetCursorPos.xaml.cs
More file actions
67 lines (58 loc) · 1.97 KB
/
GetCursorPos.xaml.cs
File metadata and controls
67 lines (58 loc) · 1.97 KB
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
using System;
using System.Threading;
using System.Windows;
namespace AlphaClicker
{
public partial class GetCursorPos: Window
{
public GetCursorPos()
{
InitializeComponent();
}
private bool enabled = true;
private void WindowHandler()
{
while (enabled)
{
Point location = WinApi.GetCursorPosition();
Dispatcher.Invoke((Action)(() =>
{
this.Left = location.X;
this.Top = location.Y;
xLbl.Content = $"X: {location.X}";
yLbl.Content = $"Y: {location.Y}";
}));
Thread.Sleep(20);
}
}
private void ClickHandler()
{
while (enabled)
{
if (WinApi.GetAsyncKeyState((int)VK.VK_LBUTTON) > 0||
WinApi.GetAsyncKeyState((int)VK.VK_ESCAPE) > 0)
{
enabled = false;
Dispatcher.Invoke((Action)(() =>
{
Point location = WinApi.GetCursorPosition();
((MainWindow)this.Owner).xBox.Text = location.X.ToString();
((MainWindow)this.Owner).yBox.Text = location.Y.ToString();
((MainWindow)this.Owner).WindowState = WindowState.Normal;
((MainWindow)this.Owner).keyEnabled = true;
Close();
}));
}
Thread.Sleep(200);
}
}
private void getCursorPosWindow_Loaded(object sender, RoutedEventArgs e)
{
((MainWindow)this.Owner).keyEnabled = false;
Thread windowHandler = new Thread(WindowHandler);
windowHandler.Start();
Thread clickhandler = new Thread(ClickHandler);
clickhandler.Start();
}
}
}