-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.cs
85 lines (77 loc) · 2.15 KB
/
Input.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
using OpenTK;
using OpenTK.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ROQWE
{
class Input
{
private static List<Key> keysDown;
private static List<Key> keysDownLast;
private static List<MouseButton> buttonsDown;
private static List<MouseButton> buttonsDownLast;
public static void Initialize(GameWindow game)
{
keysDown = new List<Key>();
keysDownLast = new List<Key>();
buttonsDown = new List<MouseButton>();
buttonsDownLast = new List<MouseButton>();
game.MouseDown += game_MouseDown;
game.MouseUp += game_MouseUp;
game.KeyDown += game_KeyDown;
game.KeyUp += game_KeyUp;
}
static void game_KeyDown(object sender, KeyboardKeyEventArgs e)
{
if (!keysDown.Contains(e.Key))
keysDown.Add(e.Key);
}
static void game_KeyUp(object sender, KeyboardKeyEventArgs e)
{
while(keysDown.Contains(e.Key))
keysDown.Remove(e.Key);
}
static void game_MouseDown(object sender, MouseButtonEventArgs e)
{
if (!buttonsDown.Contains(e.Button))
buttonsDown.Add(e.Button);
}
static void game_MouseUp(object sender, MouseButtonEventArgs e)
{
while (buttonsDown.Contains(e.Button))
buttonsDown.Remove(e.Button);
}
public static void Update()
{
keysDownLast = new List<Key>(keysDown);
buttonsDownLast = new List<MouseButton>(buttonsDown);
}
public static bool KeyPress(Key key)
{
return (keysDown.Contains(key) && !keysDownLast.Contains(key));
}
public static bool KeyRelease(Key key)
{
return (!keysDown.Contains(key) && keysDownLast.Contains(key));
}
public static bool KeyDown(Key key)
{
return (keysDown.Contains(key));
}
public static bool MousePress(MouseButton button)
{
return (buttonsDown.Contains(button) && !buttonsDownLast.Contains(button));
}
public static bool MouseRelease(MouseButton button)
{
return (!buttonsDown.Contains(button) && buttonsDownLast.Contains(button));
}
public static bool MouseDown(MouseButton button)
{
return (buttonsDown.Contains(button));
}
}
}