Skip to content

Commit e2feb86

Browse files
authored
Merge branch 'main' into main
2 parents e79947b + 803c2aa commit e2feb86

File tree

5 files changed

+123
-29
lines changed

5 files changed

+123
-29
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
README.md
2+
LICENSE
3+
.idea/
4+
*.bat
5+
*.txt
6+
*.exe
7+
*.o

README.md

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
<img width="1200" height="675" alt="disconnected_with_ban_centered_aa" src="https://github.com/user-attachments/assets/6785c5cd-f4ab-4752-aa66-b64544b8fb92" />
1+
[![testsnap](https://github.com/user-attachments/assets/ca177c81-72a4-45cf-9ac3-83f63a4d6ed2)](https://github.com/kaxlabs/SnapKeyPlus/releases)
22

3-
**About SnapKey**
3+
**About SnapKeyPlus**
44
--------------------------------------------------------------------------------------------------
5+
SnapKeyPlus extends the functionality of SnapKey by adding the pull requests everyone actually wants. 100% less self-righteousness!
6+
7+
**SnapKeyPlus enables you to play a wide variety of games. Including Marvel Rivals and CS:GO! Just run as Administrator.**
8+
59
SnapKey provides a user-friendly alternative to the Razer Snap Tap function, making it accessible across all keyboards!
610

711
SnapKey is a lightweight, open-source tool that operates from the system tray and is designed to track inputs from the WASD keys, without interfering with any game files. Its main role is to recognize when these keys are pressed and automatically release any previously engaged commands for them. This guarantees responsive and precise input handling. SnapKey handles the WASD keys by default and lets you rebind them to your liking via the config file.
@@ -11,10 +15,8 @@ SnapKey is a lightweight, open-source tool that operates from the system tray an
1115
[![COMPATIBLE](https://github.com/user-attachments/assets/069a7a23-cfe4-47eb-8ac2-05872fcc2028)](https://github.com/cafali/SnapKey/wiki/Compatibility-List)
1216

1317
### **New in v1.2.9 – Experimental VAC/CS2 Bypass Modes 🚫🎮**
14-
15-
---
16-
17-
SnapKey v1.2.9 introduces two **experimental bypass modes** aimed at improving compatibility with games that impose stricter input policies, such as **Counter-Strike 2 (CS2)**. These modes can be toggled independently in the configuration file and allow SnapKey to remain active while circumventing CS2’s built-in restrictions on background input automation.
18+
--------------------------------------------------------------------------------------------------
19+
SnapKeyPlus v1.2.9 introduces two **experimental bypass modes** aimed at improving compatibility with games that impose stricter input policies, such as **Counter-Strike 2 (CS2)**. These modes can be toggled independently in the configuration file and allow SnapKey to remain active while circumventing CS2’s built-in restrictions on background input automation.
1820

1921
> ⚙️ **VAC Bypass A** — Simulates real-time user input using a lower-level system call chain.
2022
> ⚙️ **VAC Bypass B** — Uses synthetic input injection with randomized timings to mimic human behavior more accurately.
@@ -29,19 +31,14 @@ Both modes are entirely optional and **disabled by default**. When enabled, Snap
2931
> These features are **experimental** and **not officially endorsed by Valve or any game publisher**. While SnapKey does not directly modify any game files or memory, **use of automation tools may still violate Terms of Service** for certain games.
3032
> **Use at your own risk.**
3133
32-
For details on how these bypass modes work and how to enable them, refer to the [**Bypass Modes Wiki Page**](https://github.com/cafali/SnapKey/wiki/VAC-Bypass-Modes).
33-
34-
---
35-
3634
Download
3735
--------------------------------------------------------------------------------------------------
3836
<p align="center">
39-
<a href="https://github.com/cafali/SnapKey/releases">Download from GitHub</a> |
37+
<a href="https://github.com/kaxlabs/SnapKeyPlus/releases">Download from GitHub</a> |
4038
<a href="https://sourceforge.net/projects/snapkey/">Download from SourceForge</a> |
4139
<a href="https://www.softpedia.com/get/Tweak/System-Tweak/SnapKey.shtml">Download from Softpedia</a>
4240
</p>
4341

44-
4542
[![latesver](https://github.com/user-attachments/assets/09694f7c-6eeb-4c80-9a02-1d777956d181)](https://github.com/cafali/SnapKey/wiki/Updates)
4643

4744
**SnapKey Features**
@@ -91,6 +88,38 @@ press **"A"** instead.
9188

9289
<img src="https://github.com/user-attachments/assets/4453aba4-b9bc-45e8-8a80-80caad39347b" width="600" height="338" alt="STRAFE">
9390

91+
**Quick Guide to Using SnapKey**
92+
--------------------------------------------------------------------------------------------------
93+
![use](https://github.com/user-attachments/assets/4d9fdf11-ec72-459c-995e-364bf1fc8d66)
94+
95+
1. Get SnapKey:
96+
- [Download](https://github.com/kaxlabs/SnapKeyPlus/releases), Unzip and Launch SnapKey.exe
97+
98+
<img src="https://github.com/user-attachments/assets/7f8f1b06-01a8-4bc9-af9f-87d0b19b4e15" alt="Folder" width="80%">
99+
100+
2. System Tray:
101+
- SnapKey will appear in your system tray
102+
103+
![tray](https://github.com/user-attachments/assets/26c08735-76f2-4bc0-aa75-44c9a866b453)
104+
105+
3. You're All Set:
106+
- SnapKey is now running and is ready to use
107+
108+
4. Rebind Keys (Optional):
109+
- [Rebind your keys](https://github.com/cafali/SnapKey/wiki/Rebinding-Keys) if you're using a nonstandard keyboard layout or if you want to map different keys
110+
111+
Disable SnapKey
112+
--------------------------------------------------------------------------------------------------
113+
- Double-click the tray icon to disable SnapKey directly or Right-click the SnapKey icon in the system tray and select "Disable SnapKey". This option disables the entire SnapKey functionality of the keys that are set in the config file while keeping the SnapKey process and the software running in the tray.
114+
115+
![image](https://github.com/user-attachments/assets/4f9d8d30-4674-4361-bc87-84ee70ce4116)
116+
117+
Exit SnapKey
118+
--------------------------------------------------------------------------------------------------
119+
- Right-click the SnapKey icon in the system tray and select "Exit SnapKey"
120+
121+
![image](https://github.com/user-attachments/assets/c3a9534e-ed8b-4258-be56-37b6117c1814)
122+
94123
**Linux Support**
95124
--------------------------------------------------------------------------------------------------
96125
Since SnapKey isn’t natively supported on Linux, it’s recommended to check out @Dillacorn's guide on **[running SnapKey on Linux](https://github.com/cafali/SnapKey/issues/4#issuecomment-2251568839)**.
@@ -136,17 +165,19 @@ Looking for More Information? Got Questions or Need Help?
136165
----
137166

138167
<p align="center">
139-
SnapKey by
168+
SnapKeyPlus by
140169
</p>
141170

142171
<p align="center">
143172
<a href="https://github.com/cafali">@cafali</a>
144-
<a href="https://github.com/minteeaa">@minteeaa</a>
173+
<a href="https://github.com/minteeaa">@minteeaa</a>
174+
<a href="https://github.com/kaxonomy">@kaxonomy</a>
145175
<a href="https://github.com/Yaw-Dev">@Yaw-Dev</a>
176+
<a href="https://github.com/fazildgr8">@fazildgr8</a>
146177
</p>
147178

148179
<p align="center">
149-
<a href="https://github.com/cafali/Snapkey/graphs/contributors">
150-
<img src="https://contrib.rocks/image?repo=cafali/Snapkey" />
180+
<a href="https://github.com/kaxonomy/SnapKeyPlus/graphs/contributors">
181+
<img src="https://contrib.rocks/image?repo=kaxlabs/SnapKeyPlus" />
151182
</a>
152183
</p>

SnapKey.cpp

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ void SendKey(int target, bool keyDown);
6969
void UpdateTrayIcon();
7070
void WriteConfigValue(const std::string& filename, const std::string& key, int value);
7171

72+
// Random delay settings
73+
int minDelay = 1;
74+
int maxDelay = 2;
75+
76+
void addRandomDelay()
77+
{
78+
// Create a random number generator
79+
std::random_device rd;
80+
std::mt19937 gen(rd());
81+
std::uniform_int_distribution<> dis(minDelay, maxDelay);
82+
int delayDuration = dis(gen);
83+
84+
// Sleep for the random duration
85+
std::this_thread::sleep_for(std::chrono::milliseconds(delayDuration));
86+
}
87+
7288
int main()
7389
{
7490
// Load key bindings (config file)
@@ -196,23 +212,25 @@ void handleKeyDown(int keyCode)
196212
}
197213

198214
void handleKeyUp(int keyCode)
215+
199216
{
200217
KeyState& currentKeyInfo = KeyInfo[keyCode];
218+
201219
GroupState& currentGroupInfo = GroupInfo[currentKeyInfo.group];
220+
202221
if (currentGroupInfo.previousKey == keyCode && !currentKeyInfo.keyDown)
203222
{
204223
currentGroupInfo.previousKey = 0;
205224
}
225+
206226
if (currentKeyInfo.keyDown)
207227
{
208228
currentKeyInfo.keyDown = false;
209229
if (currentGroupInfo.activeKey == keyCode && currentGroupInfo.previousKey != 0)
210230
{
211231
SendKey(keyCode, false);
212-
213232
currentGroupInfo.activeKey = currentGroupInfo.previousKey;
214233
currentGroupInfo.previousKey = 0;
215-
216234
SendKey(currentGroupInfo.activeKey, true);
217235
}
218236
else
@@ -230,13 +248,13 @@ bool isSimulatedKeyEvent(DWORD flags) {
230248

231249
void SendKey(int targetKey, bool keyDown)
232250
{
233-
INPUT input = {0};
251+
static INPUT input = {0};
234252
input.ki.wVk = targetKey;
235253
input.ki.wScan = MapVirtualKey(targetKey, 0);
236254
input.type = INPUT_KEYBOARD;
237-
238255
DWORD flags = KEYEVENTF_SCANCODE;
239256
input.ki.dwFlags = keyDown ? flags : flags | KEYEVENTF_KEYUP;
257+
addRandomDelay();
240258
SendInput(1, &input, sizeof(INPUT));
241259
}
242260

@@ -245,11 +263,18 @@ LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
245263
if (!isLocked && nCode >= 0)
246264
{
247265
KBDLLHOOKSTRUCT *pKeyBoard = (KBDLLHOOKSTRUCT *)lParam;
248-
if (!isSimulatedKeyEvent(pKeyBoard -> flags)) {
249-
if (KeyInfo[pKeyBoard -> vkCode].registered)
266+
if (!isSimulatedKeyEvent(pKeyBoard->flags))
267+
{
268+
if (KeyInfo[pKeyBoard->vkCode].registered)
250269
{
251-
if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) handleKeyDown(pKeyBoard -> vkCode);
252-
if (wParam == WM_KEYUP || wParam == WM_SYSKEYUP) handleKeyUp(pKeyBoard -> vkCode);
270+
if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)
271+
{
272+
handleKeyDown(pKeyBoard->vkCode);
273+
}
274+
if (wParam == WM_KEYUP || wParam == WM_SYSKEYUP)
275+
{
276+
handleKeyUp(pKeyBoard->vkCode);
277+
}
253278
return 1;
254279
}
255280
}
@@ -366,7 +391,12 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
366391
break;
367392
case ID_TRAY_REBIND_KEYS: // rebind keys - open cfg
368393
{
369-
ShellExecute(NULL, TEXT("open"), TEXT("config.cfg"), NULL, NULL, SW_SHOWNORMAL);
394+
TCHAR szExeFileName[MAX_PATH];
395+
GetModuleFileName(NULL, szExeFileName, MAX_PATH);
396+
std::string exePath = std::string(szExeFileName);
397+
std::string exeDir = exePath.substr(0, exePath.find_last_of("\\/"));
398+
std::string configPath = exeDir + "\\config.cfg";
399+
ShellExecute(NULL, TEXT("open"), configPath.c_str(), NULL, NULL, SW_SHOWNORMAL);
370400
}
371401
break;
372402

@@ -442,16 +472,22 @@ std::string GetVersionInfo() {
442472
// Function to copy snapkey.backup (meta folder) to the main directory
443473
void RestoreConfigFromBackup(const std::string& backupFilename, const std::string& destinationFilename)
444474
{
445-
std::string sourcePath = "meta\\" + backupFilename;
446-
std::string destinationPath = destinationFilename;
475+
// Get the executable path
476+
char exePath[MAX_PATH];
477+
GetModuleFileName(NULL, exePath, MAX_PATH);
478+
std::string exeDir = std::string(exePath);
479+
exeDir = exeDir.substr(0, exeDir.find_last_of("\\/"));
480+
481+
std::string sourcePath = exeDir + "\\meta\\" + backupFilename;
482+
std::string destinationPath = exeDir + "\\" + destinationFilename;
447483

448484
if (CopyFile(sourcePath.c_str(), destinationPath.c_str(), FALSE)) {
449485
// Copy successful
450486
MessageBox(NULL, TEXT("Default config restored from backup successfully."), TEXT("SnapKey"), MB_ICONINFORMATION | MB_OK);
451487
} else {
452488
// backup.snapkey copy failed
453489
DWORD error = GetLastError();
454-
std::string errorMsg = "Failed to restore config from backup.";
490+
std::string errorMsg = "Failed to restore config from backup. Error code: " + std::to_string(error);
455491
MessageBox(NULL, errorMsg.c_str(), TEXT("SnapKey Error"), MB_ICONERROR | MB_OK);
456492
}
457493
}
@@ -460,6 +496,7 @@ void RestoreConfigFromBackup(const std::string& backupFilename, const std::strin
460496
void CreateDefaultConfig(const std::string& filename)
461497
{
462498
std::string backupFilename = "backup.snapkey";
499+
// Just pass the filenames, as RestoreConfigFromBackup now handles the full paths
463500
RestoreConfigFromBackup(backupFilename, filename);
464501
}
465502

@@ -495,7 +532,15 @@ void WriteConfigValue(const std::string& filename, const std::string& key, int v
495532
// Check for config.cfg
496533
bool LoadConfig(const std::string& filename)
497534
{
498-
std::ifstream configFile(filename);
535+
// Get the executable path
536+
char exePath[MAX_PATH];
537+
GetModuleFileName(NULL, exePath, MAX_PATH);
538+
std::string exeDir = std::string(exePath);
539+
exeDir = exeDir.substr(0, exeDir.find_last_of("\\/"));
540+
541+
std::string fullPath = exeDir + "\\" + filename;
542+
543+
std::ifstream configFile(fullPath);
499544
if (!configFile.is_open()) {
500545
CreateDefaultConfig(filename); // Restore config from backup.snapkey if file doesn't exist
501546
return false;
@@ -552,6 +597,15 @@ bool LoadConfig(const std::string& filename)
552597
vacBMaxDelay = value; foundBMax = true;
553598
}
554599
}
600+
if (line.find("random_delay_ms=") == 0)
601+
{
602+
std::smatch match;
603+
std::regex delayPattern(R"(\s*(\d+)\s*,\s*(\d+)\s*)");
604+
if (std::regex_search(line, match, delayPattern) && match.size()) {
605+
minDelay = std::stoi(match[1].str());
606+
maxDelay = std::stoi(match[2].str());
607+
}
608+
}
555609
}
556610
configFile.close();
557611

config.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ key2=68
66
key3=83
77
key4=87
88

9+
random_delay_ms=(1,2)
910

1011
# After applying the changes, please restart SnapKey.
1112
# For further help, visit the README.pdf file.

meta/backup.snapkey

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ key2=68
66
key3=83
77
key4=87
88

9+
random_delay_ms=(1,2)
910

1011
# After applying the changes, please restart SnapKey.
1112
# For further help, visit the README.pdf file.

0 commit comments

Comments
 (0)