forked from SplitScreen-Me/splitscreenme-protoInput
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFakeMouseKeyboard.h
More file actions
92 lines (74 loc) · 2.79 KB
/
Copy pathFakeMouseKeyboard.h
File metadata and controls
92 lines (74 loc) · 2.79 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
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
#pragma once
#include <bitset>
namespace Proto
{
struct FakeMouseState
{
int x, y;
int clipClientLeft;
int clipClientTop;
int clipClientRight;
int clipClientBottom;
bool hasClipCursor = false;
bool ignoreMouseBounds = false;
bool extendMouseBounds = false;
};
struct FakeKeyboardState
{
// GetAyncKeyState will tell the caller
// 1. Whether the key is pressed
// 2. Whether the key has been pressed during the time since the last call to GetAsyncKeyState
// (The key doesn't have to currently be pressed for this to be true)
//
// To emulate this, take two buffers:
// keysState records the physical state of the keyboard. It is changed whenever a key is pressed or released
// asyncKeysState records whether the keys were pressed since the last call.
// The buffer is only set to true when a key is pressed (releasing a key does nothing)
// The buffer is then wiped at the end of the GetAsyncKeyState hook
std::bitset<256> keysState{};
std::bitset<256> asyncKeysState{};
};
class FakeMouseKeyboard
{
static FakeMouseState mouseState;
static FakeKeyboardState keyboardState;
public:
static const FakeMouseState& GetMouseState() { return mouseState; }
//static const FakeKeyboardState& GetKeyBoardState() { return keyboardState; }
static void AddMouseDelta(int dx, int dy);
static void SetMousePos(int x, int y);
static void SetClipCursor(int clientLeft, int clientTop, int clientRight, int clientBottom);
static void RemoveClipCursor();
static void SetIgnoreMouseBounds(bool ignore);
static void SetExtendMouseBounds(bool extend);
static void ReceivedKeyPressOrRelease(int vkey, bool pressed);
static void ClearAsyncKeyState(int vkey);
static bool IsKeyStatePressed(int vkey);
static bool IsAsyncKeyStatePressed(int vkey);
static bool IsExtendedKeyStatePressed(int vkey); //To use the exteended key flag (like arrow keys)
// Some games must use the exact window rect to determine the edge of the window.
static bool PutMouseInsideWindow;
// IgnoreTopLeft and IgnoreBottomRight for PutMouseInsideWindow
static bool DefaultTopLeftMouseBounds;
static bool DefaultBottomRightMouseBounds;
static unsigned int GetMouseMkFlags()
{
#define PROTO_MMFKEY(x, y) ((FakeMouseKeyboard::IsKeyStatePressed(x)) ? (y) : (0))
// return PROTO_MMFKEY(VK_CONTROL, MK_CONTROL) |
// PROTO_MMFKEY(VK_SHIFT, MK_SHIFT) |
// PROTO_MMFKEY(VK_LBUTTON, MK_LBUTTON) |
// PROTO_MMFKEY(VK_MBUTTON, MK_MBUTTON) |
// PROTO_MMFKEY(VK_RBUTTON, MK_RBUTTON) |
// PROTO_MMFKEY(VK_XBUTTON1, MK_XBUTTON1) |
// PROTO_MMFKEY(VK_XBUTTON2, MK_XBUTTON2);
return PROTO_MMFKEY(0x11, 0x0008) |
PROTO_MMFKEY(0x10, 0x0004) |
PROTO_MMFKEY(0x01, 0x0001) |
PROTO_MMFKEY(0x04, 0x0010) |
PROTO_MMFKEY(0x02, 0x0002) |
PROTO_MMFKEY(0x05, 0x0020) |
PROTO_MMFKEY(0x06, 0x0040);
#undef PROTO_MMFKEY
}
};
}