Created
October 23, 2023 01:26
-
-
Save petersvp/2bb94fa962f232456519630ed4c0103a to your computer and use it in GitHub Desktop.
C++ bot that plays Reaction Time in HumanBenchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <iostream> | |
#include "stdio.h" | |
#include <vector> | |
using namespace std; | |
int main() | |
{ | |
// Windows only! | |
// To get <16ms with this: | |
// | |
// 1. DISABLE all extra monitors | |
// 2. Switch to the fastest refresh rate you can get, 240fps displays take precedence | |
// 3. Close literally everything, especially streaming software and Discord! | |
// 4. Build in Release mode as GUI APP, run and set the executable priority to preferably Realtime (24) | |
// => GetPixel() call will make a thread switch and even VBLANK wait on some machines (CPU 100% vs CPU 0%) | |
// 5. Hide desktop icons and close Windows Explorer (focus Desktop, Hit Alt+F4 and in the Shut Down prompt hold Alt+Ctrl+Shift and click CANCEL) | |
// For even better result compile as a GUI app and kill using Task Manager. Always use Release Mode. | |
// If you want to record this test use any indirect or man-in-the-middle methods | |
// => Phone against display, or a capture card. | |
// To run: start this app, open the website, start the reaction test and | |
// keep the mouse pointer over the playfield pixel that will become GREEN - | |
// => the app uses pixel over the cursor to determine when to click | |
// Now here's how it works | |
// Termorary colorref and our expected green color magic number | |
COLORREF c, reaction_expected_color = 7002955; | |
POINT pos; | |
// Get Desktop's context forr reading colors from it as fast as computationally possible | |
HDC dc = GetDC(NULL); | |
while (true) // just close the app via Task Manager or its console window - any bit of performance is important so no GetAsyncKeyState | |
{ | |
GetCursorPos(&pos); // Calls into Kernel Mode but seems to be fast enough to care | |
c = GetPixel(dc, pos.x, pos.y); // Calls into Kernel Mode and video drivers and yields current process... | |
if (c == reaction_expected_color) // intrinsic, jcmp instruction | |
{ | |
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); | |
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); | |
Sleep(500); // here we don't care about performance but for the user to be able to see the ms | |
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); | |
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); | |
} | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment