-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputManager.cpp
More file actions
64 lines (56 loc) · 1.76 KB
/
InputManager.cpp
File metadata and controls
64 lines (56 loc) · 1.76 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
// InputManager.cpp
#include <iostream>
#include <conio.h> // For _kbhit() and _getch()
#include <windows.h> // For mouse input
class InputManager {
public:
InputManager() {
// Initialize any necessary variables or states
}
void update() {
handleKeyboardInput();
handleMouseInput();
}
private:
void handleKeyboardInput() {
if (_kbhit()) { // Check if a key has been pressed
char key = _getch(); // Get the pressed key
switch (key) {
case 'w': // Move forward
std::cout << "Moving forward" << std::endl;
break;
case 's': // Move backward
std::cout << "Moving backward" << std::endl;
break;
case 'a': // Turn left
std::cout << "Turning left" << std::endl;
break;
case 'd': // Turn right
std::cout << "Turning right" << std::endl;
break;
case ' ': // Fire weapon
std::cout << "Firing weapon" << std::endl;
break;
default:
break;
}
}
}
void handleMouseInput() {
// Example of mouse input handling
POINT cursorPos;
if (GetCursorPos(&cursorPos)) {
// Process mouse position
std::cout << "Mouse Position: (" << cursorPos.x << ", " << cursorPos.y << ")" << std::endl;
}
// Here you can add more mouse input handling logic (e.g., mouse clicks)
}
};
int main() {
InputManager inputManager;
while (true) {
inputManager.update();
Sleep(100); // Sleep to reduce CPU usage
}
return 0;
}