forked from prototype99/dsfix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
KeyActions.cpp
73 lines (73 loc) · 2.17 KB
/
KeyActions.cpp
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
#include "KeyActions.h"
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
#include "main.h"
#include "WindowManager.h"
#include "Settings.h"
#include "RenderstateManager.h"
KeyActions KeyActions::instance;
void KeyActions::load() {
std::ifstream sfile;
sfile.open(GetDirectoryFile("DSfixKeys.ini"), std::ios::in);
char buffer[256];
while(!sfile.eof()) {
sfile.getline(buffer, 256);
if(buffer[0] == '#') continue;
if(sfile.gcount() <= 1) continue;
string bstring(buffer);
size_t pos = bstring.npos;
char postChar;
#define KEY(_name, _val) \
pos = bstring.find(#_name); \
postChar = buffer[pos + strlen(#_name)]; \
if(pos != bstring.npos && (postChar == '\r' || postChar == '\n' || postChar == ' ' || postChar == '\0')) { \
string action; stringstream ss(bstring); ss >> action; \
keyBindingMap.insert(make_pair(_val, action)); \
}
#include "Keys.def"
#undef KEY
}
sfile.close();
}
void KeyActions::report() {
SDLOG(0, "= Loaded Keybindings:\n");
for(IntStrMap::const_iterator i = keyBindingMap.begin(); i != keyBindingMap.end(); ++i) {
SDLOG(0, " - %p => %s\n", i->first, i->second.c_str());
}
SDLOG(0, "=============\n");
SDLOG(5, "= Possible Actions:\n");
#define ACTION(_name, _action) \
SDLOG(5, "%s, ", #_name);
#include "Actions.def"
#undef ACTION
SDLOG(5, "=============\n");
SDLOG(5, "= Possible Keys:\n");
#define KEY(_name, _val) \
SDLOG(5, "%s, ", #_name);
#include "Keys.def"
#undef KEY
SDLOG(5, "=============\n");
}
void KeyActions::performAction(const char* name) {
#define ACTION(_name, _action) \
if(strcmp(#_name, name) == 0) _name();
#include "Actions.def"
#undef ACTION
}
void KeyActions::processIO() {
if(::GetForegroundWindow() != NULL && ::GetActiveWindow() != NULL) {
for(IntStrMap::const_iterator i = keyBindingMap.begin(); i != keyBindingMap.end(); ++i) {
if(GetAsyncKeyState(i->first)&1) {
SDLOG(0, "Action triggered: %s\n", i->second.c_str());
performAction(i->second.c_str());
}
}
}
}
#define ACTION(_name, _action) \
void KeyActions::##_name() { _action; };
#include "Actions.def"
#undef ACTION