-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainWindow.xaml.cs
144 lines (118 loc) · 4.13 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
143
144
using SharpDX.XInput;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
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 WindowsInput;
namespace UP_pad
{
public partial class MainWindow : Window
{
private Controller controller;
private IMouseSimulator mouseSimulator;
private Timer timer;
private bool aWasDown, bWasDown;
public MainWindow()
{
InitializeComponent();
controller = new Controller(UserIndex.One);
mouseSimulator = new InputSimulator().Mouse;
timer = new Timer(obj => Update());
Start();
}
private void Start()
{
timer.Change(0, 1000 / 60);
}
private void Update()
{
controller.GetState(out var state);
Movement(state);
Scroll(state);
LeftBtn(state);
RightBtn(state);
ColorChange(state);
}
private void ColorChange(State state)
{
var xDown = state.Gamepad.Buttons.HasFlag(GamepadButtonFlags.X);
var yDown = state.Gamepad.Buttons.HasFlag(GamepadButtonFlags.Y);
if(xDown)
{
drawingBoard.Dispatcher.Invoke(() => { drawingBoard.DefaultDrawingAttributes.Color = Colors.Blue; });
}
if(yDown)
{
drawingBoard.Dispatcher.Invoke(() => { drawingBoard.DefaultDrawingAttributes.Color = Colors.Yellow; });
}
}
private void Movement(State state)
{
var x = state.Gamepad.LeftThumbX / 2_000;
var y = state.Gamepad.LeftThumbY / 2_000;
mouseSimulator.MoveMouseBy(x, -y);
xAxis.Dispatcher.Invoke(() => { xAxis.Text = (state.Gamepad.LeftThumbX.ToString()); });
yAxis.Dispatcher.Invoke(() => { yAxis.Text = (state.Gamepad.LeftThumbY.ToString()); });
}
private void Scroll(State state)
{
var x = state.Gamepad.RightThumbX / 10_000;
var y = state.Gamepad.RightThumbY / 10_000;
mouseSimulator.HorizontalScroll(x);
mouseSimulator.VerticalScroll(y);
}
private void LeftBtn(State state)
{
var aDown = state.Gamepad.Buttons.HasFlag(GamepadButtonFlags.A);
if (aDown && !aWasDown)
{
mouseSimulator.LeftButtonDown();
CheckA.Dispatcher.Invoke(() => { CheckA.IsChecked = true; });
}
if (!aDown && aWasDown)
{
mouseSimulator.LeftButtonUp();
CheckA.Dispatcher.Invoke(() => { CheckA.IsChecked = false; });
}
aWasDown = aDown;
}
private void CheckBox_A(object sender, RoutedEventArgs e)
{
}
private void CheckBox_B(object sender, RoutedEventArgs e)
{
}
private void Button_Click(object sender, RoutedEventArgs e)
{
drawingBoard.Strokes.Clear();
drawingBoard.DefaultDrawingAttributes.Color = Colors.Red;
}
private void RightBtn(State state)
{
var bDown = state.Gamepad.Buttons.HasFlag(GamepadButtonFlags.B);
if (bDown && !bWasDown)
{
mouseSimulator.RightButtonDown();
CheckB.Dispatcher.Invoke(() => { CheckB.IsChecked = true; });
}
if (!bDown && bWasDown)
{
mouseSimulator.RightButtonUp();
CheckB.Dispatcher.Invoke(() => { CheckB.IsChecked = false; });
}
bWasDown = bDown;
}
}
}