11#include " keybinds.h"
22#include < Windows.h>
3+ #include < cstring> // For strcpy_s and sprintf_s
4+ #include < cstdio> // For sprintf_s
35
46#include " ../../../external/imgui/imgui.h"
57#include " ../config/config.h"
@@ -8,39 +10,73 @@ Keybind::Keybind(bool& v, int k)
810 : var(v), key(k), isListening(false ), skipFrame(false ) {}
911
1012Keybinds::Keybinds () {
11- keybinds.emplace_back (Keybind (Config::aimbot, VK_INSERT ));
13+ keybinds.emplace_back (Keybind (Config::aimbot, VK_XBUTTON1 ));
1214}
1315
1416void Keybinds::pollInputs () {
15- for (Keybind& k : keybinds) {
16- if (GetAsyncKeyState (k.key ) & 1 ) {
17- k.var = !k.var ;
18- }
19- }
17+ for (Keybind& k : keybinds) {
18+ if (k. key != 0 && ( GetAsyncKeyState (k.key ) & 0x1 ) ) {
19+ k.var = !k.var ;
20+ }
21+ }
2022}
2123
2224void Keybinds::menuButton (bool & var) {
2325 for (auto & kb : keybinds) {
2426 if (&kb.var != &var) continue ;
2527
28+ char keyName[32 ] = " None" ;
29+ if (kb.key != 0 ) {
30+ switch (kb.key ) {
31+ case VK_INSERT: strcpy_s (keyName, " INSERT" ); break ;
32+ case VK_DELETE: strcpy_s (keyName, " DELETE" ); break ;
33+ case VK_HOME: strcpy_s (keyName, " HOME" ); break ;
34+ case VK_END: strcpy_s (keyName, " END" ); break ;
35+ case VK_PRIOR: strcpy_s (keyName, " PAGE UP" ); break ;
36+ case VK_NEXT: strcpy_s (keyName, " PAGE DOWN" ); break ;
37+ case VK_LBUTTON: strcpy_s (keyName, " MOUSE1" ); break ;
38+ case VK_RBUTTON: strcpy_s (keyName, " MOUSE2" ); break ;
39+ case VK_MBUTTON: strcpy_s (keyName, " MOUSE3" ); break ;
40+ case VK_XBUTTON1: strcpy_s (keyName, " MOUSE4" ); break ;
41+ case VK_XBUTTON2: strcpy_s (keyName, " MOUSE5" ); break ;
42+ default :
43+ if (kb.key >= ' A' && kb.key <= ' Z' ) {
44+ sprintf_s (keyName, " %c" , kb.key );
45+ }
46+ else if (kb.key >= ' 0' && kb.key <= ' 9' ) {
47+ sprintf_s (keyName, " %c" , kb.key );
48+ }
49+ else {
50+ sprintf_s (keyName, " 0x%X" , kb.key );
51+ }
52+ break ;
53+ }
54+ }
55+
2656 if (!kb.isListening ) {
27- if (ImGui::Button (" Bind" )) {
57+ ImGui::PushID (&kb);
58+ ImGui::Text (" [%s]" , keyName);
59+ ImGui::SameLine ();
60+ bool clicked = ImGui::Button (" Change##Bind" );
61+ ImGui::PopID ();
62+
63+ if (clicked) {
2864 kb.isListening = true ;
2965 kb.skipFrame = true ;
3066 }
3167 }
3268 else {
33- ImGui::Text (" Press any key (ESC to cancel) ..." );
69+ ImGui::Text (" Press any key..." );
3470 ImGui::SameLine ();
3571
36- if (ImGui::Button (" Cancel" ) || (GetAsyncKeyState (VK_ESCAPE) & 1 )) {
72+ if (ImGui::Button (" Cancel" ) || (GetAsyncKeyState (VK_ESCAPE) & 0x8000 )) {
3773 kb.isListening = false ;
3874 return ;
3975 }
4076
4177 if (!kb.skipFrame ) {
4278 for (int keyCode = 7 ; keyCode < 256 ; ++keyCode) {
43- if (GetAsyncKeyState (keyCode)) {
79+ if (GetAsyncKeyState (keyCode) & 0x8000 ) {
4480 kb.key = keyCode;
4581 kb.isListening = false ;
4682 return ;
@@ -55,4 +91,4 @@ void Keybinds::menuButton(bool& var) {
5591}
5692
5793
58- Keybinds keybind;
94+ Keybinds keybind;
0 commit comments