-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.h
235 lines (225 loc) · 5.71 KB
/
util.h
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#pragma once
#define SDL_MAIN_HANDLED
#define VERSION "v1.2"
#include <map>
#include <windows.h>
#include <WinUser.h>
#include <stdio.h>
#include <iostream>
#include "minini_13/minIni.h"
#include "imgui.h"
#include "imgui_impl_sdl2.h"
#include "imgui_impl_opengl3.h"
#include <stdio.h>
#include <SDL.h>
#if defined(IMGUI_IMPL_OPENGL_ES2)
#include <SDL_opengles2.h>
#else
#include <SDL_opengl.h>
#endif
std::map<int, const char *> vkCodeToKeyName = {
{0x08, "BACKSPACE"},
{0x09, "TAB"},
{0x0D, "ENTER"},
{0x10, "SHIFT"},
{0x0C, "CLEAR"},
{0x0D, "ENTER"},
{0x10, "SHIFT"},
{0x11, "CTRL"},
{0x12, "ALT"},
{0x13, "PAUSE"},
{0x14, "CAPS LOCK"},
{0x15, "IME kana"},
{0x16, "IME Hangul"},
{0x17, "IME Junja"},
{0x18, "IME Final"},
{0x19, "IME Kanji"},
{0x1A, "IME Off"},
{0x1B, "ESC"},
{0x1C, "IME Convert"},
{0x1D, "IME Nonconvert"},
{0x1E, "IME Accept"},
{0x1F, "IME Mode Change"},
{0x20, "SPACE"},
{0x21, "PAGE UP"},
{0x22, "PAGE DOWN"},
{0x23, "END"},
{0x24, "HOME"},
{0x25, "LEFT"},
{0x26, "UP"},
{0x27, "RIGHT"},
{0x28, "DOWN"},
{0x29, "SELECT"},
{0x2A, "PRINT"},
{0x2B, "EXECUTE"},
{0x2C, "PRINT SCREEN"},
{0x2D, "INSERT"},
{0x2E, "DELETE"},
{0x2F, "HELP"},
{0x30, "KEY_0"},
{0x31, "KEY_1"},
{0x32, "KEY_2"},
{0x33, "KEY_3"},
{0x34, "KEY_4"},
{0x35, "KEY_5"},
{0x36, "KEY_6"},
{0x37, "KEY_7"},
{0x38, "KEY_8"},
{0x39, "KEY_9"},
{0x41, "A"},
{0x42, "B"},
{0x43, "C"},
{0x44, "D"},
{0x45, "E"},
{0x46, "F"},
{0x47, "G"},
{0x48, "H"},
{0x49, "I"},
{0x4A, "J"},
{0x4B, "K"},
{0x4C, "L"},
{0x4D, "M"},
{0x4E, "N"},
{0x4F, "O"},
{0x50, "P"},
{0x51, "Q"},
{0x52, "R"},
{0x53, "S"},
{0x54, "T"},
{0x55, "U"},
{0x56, "V"},
{0x57, "W"},
{0x58, "X"},
{0x59, "Y"},
{0x5A, "Z"},
{0x5B, "LWIN"},
{0x5C, "RWIN"},
{0x5D, "APPS"},
{0x60, "NUMPAD0"},
{0x61, "NUMPAD1"},
{0x62, "NUMPAD2"},
{0x63, "NUMPAD3"},
{0x64, "NUMPAD4"},
{0x65, "NUMPAD5"},
{0x66, "NUMPAD6"},
{0x67, "NUMPAD7"},
{0x68, "NUMPAD8"},
{0x69, "NUMPAD9"},
{0x6A, "MULTIPLY"},
{0x6B, "ADD"},
{0x6C, "SEPARATOR"},
{0x6D, "SUBTRACT"},
{0x6E, "DECIMAL"},
{0x6F, "DIVIDE"},
{0x70, "F1"},
{0x71, "F2"},
{0x72, "F3"},
{0x73, "F4"},
{0x74, "F5"},
{0x75, "F6"},
{0x76, "F7"},
{0x77, "F8"},
{0x78, "F9"},
{0x79, "F10"},
{0x7A, "F11"},
{0x7B, "F12"},
{0x7C, "F13"},
{0x7D, "F14"},
{0x7E, "F15"},
{0x7F, "F16"},
{0x80, "F17"},
{0x81, "F18"},
{0x82, "F19"},
{0x83, "F20"},
{0x84, "F21"},
{0x85, "F22"},
{0x86, "F23"},
{0x87, "F24"},
{0x90, "NUM LOCK"},
{0x91, "SCROLL LOCK"},
{0x92, "NUMPAD_EQUAL"},
{0x93, "NUMPAD_MULTIPLY"},
{0x94, "NUMPAD_ADD"},
{0x95, "NUMPAD_SEPARATOR"},
{0x96, "NUMPAD_SUBTRACT"},
{0x97, "NUMPAD_DECIMAL"},
{0x98, "NUMPAD_DIVIDE"},
{0xA0, "LSHIFT"},
{0xA1, "RSHIFT"},
{0xA2, "LCONTROL"},
{0xA3, "RCONTROL"},
{0xA4, "LMENU"},
{0xA5, "RMENU"},
{0xBA, "OEM_1"},
{0xBB, "OEM_PLUS"},
{0xBC, "OEM_COMMA"},
{0xBD, "OEM_MINUS"},
{0xBE, "OEM_PERIOD"},
{0xBF, "OEM_2"},
{0xC0, "OEM_3"},
{0xDB, "OEM_4"},
{0xDC, "OEM_5"},
{0xDD, "OEM_6"},
{0xDE, "OEM_7"},
{0xDF, "OEM_8"},
{0xE2, "OEM_102"}};
// config
// [data]
static int key_vkcode_config[9] = {83, 68, 70, 32, 74, 75, 76, 77, 78};
static int key_button_config[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
static int key_press_count[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
// [Key overlay]
static int key_style = 1; // 显示按键布局 0一条线 1iidx默认布局 2平铺
static bool key_color_style = 1; // 显示按键颜色 0单色 1默认红蓝
static int play_position = 0; // iidx游玩位置 0 1p 1 2p
static int btn_size_x = 30;
static int btn_size_y = 60;
static int sbtn_size_x = 60;
static int sbtn_size_y = 70;
static int key_dummy_size = 15; // iidx默认布局横向填充空白大小
static bool key_count_num = true;
// [histogram]
static int histogram_height = 130;
static int press_time_scale = 200;
// [KPS]
static int kps_fresh_frame = 30;
static int kps_plot_length = 80;
// [input mode]
static int input_mode = 0; // 输入模式 0键盘 1控制器
static int joystick_no = 0;
static int joystick_max_position = 32768; // 最大值
static int joystick_scr_threshold = 3000;
static int frame_threshold = 4;
// 全局变量
const char *ini_file = "./config.ini";
static float f = 0.0f;
static int counter = 0; // fps计算
bool main_window_close_flag = true;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 0.00f);
static float _histogram_values[8] = {};
static bool is_key_pressed[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
static int key_pressed_window_time[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
static HHOOK hHook = NULL;
static int key_to_bind = -1; // 待绑定按键编号 -1为无
static int key_frame_count = 0;
static int _count = 0;
static float kps = 0;
static int currentIdx = 0;
static int count_sum = 0;
static std::string msg;
float kpsHistory[500] = {0};
SDL_Joystick *gGameController = NULL;
static int joystick_current_pos = 0;
static int joystick_last_position = 0; // 存储上一次的位置
static int joystick_accumulated_difference = 0; // 累积的差值
static int joystick_frame_count = 0; // 帧计数器
static int joystick_axis_no = 0;
static void handle_hook_key_press(WPARAM, DWORD);
static void HelpMarker(const char *desc);
LRESULT CALLBACK KeyboardProc(int, WPARAM, LPARAM);
void SetGlobalHook();
void RemoveGlobalHook();
void LoadConfig();
void SaveConfig(bool);
void SetDefaultConfig(bool);
void InitController();