Repository navigation
Expand file tree
/
Copy pathapifuncs.h
More file actions
103 lines (102 loc) · 3.74 KB
/
Copy pathapifuncs.h
File metadata and controls
103 lines (102 loc) · 3.74 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
93
94
95
96
97
98
99
100
101
102
103
#pragma once
#include "../XMapLib/MouseMapper.h"
#include "../XMapLib/KeyboardMapper.h"
#include "helperfuncs.h"
extern "C"
{
namespace StaticInstance
{
using LockType = std::scoped_lock <std::mutex>;
inline std::mutex accessBlocker;
inline sds::KeyboardMapper kbd;
inline sds::MouseMapper mmp;
inline std::string mapInfoFormatted;
}
__declspec(dllexport) inline void XMapLibInitBoth()
{
StaticInstance::LockType tempLock(StaticInstance::accessBlocker);
StaticInstance::kbd.Start();
StaticInstance::mmp.Start();
}
__declspec(dllexport) inline void XMapLibInitMouse()
{
StaticInstance::LockType tempLock(StaticInstance::accessBlocker);
StaticInstance::mmp.Start();
}
__declspec(dllexport) inline void XMapLibStopMouse()
{
StaticInstance::LockType tempLock(StaticInstance::accessBlocker);
StaticInstance::mmp.Stop();
}
__declspec(dllexport) inline void XMapLibInitKeyboard()
{
StaticInstance::LockType tempLock(StaticInstance::accessBlocker);
StaticInstance::kbd.Start();
}
__declspec(dllexport) inline void XMapLibStopKeyboard()
{
StaticInstance::LockType tempLock(StaticInstance::accessBlocker);
StaticInstance::kbd.Stop();
}
__declspec(dllexport) inline void XMapLibStopBoth()
{
StaticInstance::LockType tempLock(StaticInstance::accessBlocker);
StaticInstance::kbd.Stop();
StaticInstance::mmp.Stop();
}
__declspec(dllexport) inline bool XMapLibAddMap(int vkSender, int vkMapping, bool bUsesRepeat)
{
StaticInstance::LockType tempLock(StaticInstance::accessBlocker);
return StaticInstance::kbd.AddMap(sds::KeyboardKeyMap(vkSender, vkMapping, bUsesRepeat)).empty();
}
__declspec(dllexport) inline void XMapLibClearMaps()
{
StaticInstance::LockType tempLock(StaticInstance::accessBlocker);
StaticInstance::kbd.ClearMaps();
}
__declspec(dllexport) inline const char * XMapLibGetMaps()
{
StaticInstance::LockType tempLock(StaticInstance::accessBlocker);
const std::vector<sds::KeyboardKeyMap> maps = StaticInstance::kbd.GetMaps();
std::string localString;
for (const auto &lmp : maps)
localString << lmp;
StaticInstance::mapInfoFormatted = localString;
return StaticInstance::mapInfoFormatted.data();
}
__declspec(dllexport) inline bool XMapLibIsControllerConnected()
{
StaticInstance::LockType tempLock(StaticInstance::accessBlocker);
return StaticInstance::kbd.IsControllerConnected() && StaticInstance::mmp.IsControllerConnected();
}
__declspec(dllexport) inline bool XMapLibIsMouseRunning()
{
StaticInstance::LockType tempLock(StaticInstance::accessBlocker);
return StaticInstance::mmp.IsRunning();
}
__declspec(dllexport) inline bool XMapLibIsKeyboardRunning()
{
StaticInstance::LockType tempLock(StaticInstance::accessBlocker);
return StaticInstance::kbd.IsRunning();
}
__declspec(dllexport) inline void XMapLibSetMouseStick(int whichStick)
{
StaticInstance::LockType tempLock(StaticInstance::accessBlocker);
//ensure same underlying integral type, and that sds::StickMap is still an enum
using StickType = std::underlying_type_t<sds::StickMap>;
static_assert(std::is_enum_v<sds::StickMap>, "ensure sds::StickMap is still an enum");
static_assert(std::is_same_v<StickType, decltype(whichStick)>, "ensure interface type and sds::StickMap enum underlying type are the same");
//pass along the (possibly arbitrary) value to the MouseMapper.
StaticInstance::mmp.SetStick(static_cast<sds::StickMap>(whichStick));
}
__declspec(dllexport) inline bool XMapLibSetMouseSensitivity(int sens)
{
StaticInstance::LockType tempLock(StaticInstance::accessBlocker);
return StaticInstance::mmp.SetSensitivity(sens).empty();
}
__declspec(dllexport) inline int XMapLibGetMouseSensitivity()
{
StaticInstance::LockType tempLock(StaticInstance::accessBlocker);
return StaticInstance::mmp.GetSensitivity();
}
}