Files
scripts/cpp/spinner.cpp

44 lines
991 B
C++
Executable File

#include <Windows.h>
#include <cstdio>
#include <cmath>
#include <tuple>
constexpr auto num_points = 10;
constexpr auto sleep_msec = 1;
constexpr auto radius = 100.0f;
int main() {
const auto window_handle = FindWindow(nullptr, "osu!");
if (!window_handle) {
printf("FATAL: Could not find osu!. (0x%X)\n", GetLastError());
return -1;
}
auto get_desired_pos = [&]() -> std::tuple<int, int> {
static auto counter = 0;
counter++;
RECT rect;
GetWindowRect(window_handle, &rect);
const auto center_x = rect.left + (rect.right - rect.left) / 2;
const auto center_y = rect.top + (rect.bottom - rect.top) / 2;
const auto angle = 3.1415926f * 2.0f * (float)counter / (float)num_points;
if (counter > num_points) {
counter = 0;
}
return { center_x + radius * sin(angle), center_y + radius * cos(angle) };
};
while (!GetAsyncKeyState(VK_DELETE)) {
if (GetAsyncKeyState('P')) {
std::apply(SetCursorPos, get_desired_pos());
}
Sleep(sleep_msec);
}
}