Skip to content

Commit

Permalink
Timed Auto Click
Browse files Browse the repository at this point in the history
Added the ability to run the autoclicker for only x amount of seconds.
  • Loading branch information
ryandw11 committed Dec 14, 2021
1 parent 16fad5c commit f51c327
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 15 deletions.
66 changes: 54 additions & 12 deletions AutoClickerDL/AutoClickerDL.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

#include <stdio.h>
#include <time.h>
#include <Windows.h>
#include <Commctrl.h>
#include <Shlobj.h>
Expand All @@ -16,6 +17,8 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#define WIDTH 400
#define HEIGHT 500

#define SETTINGS_TIMED_CHECK_BOX 1

// The handle to the main window.
HWND mainWindowHandle;

Expand All @@ -24,11 +27,12 @@ HWND tabControl, generalDisplayArea, settingsDisplayArea, rememberClickDisplayAr

// The hotkey control for the start/stop of the Auto Clicker.
HWND startStopHotKey;
// The spinner for clicks per second.
HWND spinnerHWD;
// The spinners
HWND cpsSpinnerHWD, timedAutoSpinnerHWD;

// The timer used by the clicker. Not null when enabled, NULL when not enabled.
UINT_PTR autoClickerTimer = NULL;
time_t startClickerTime;

// Process callbacks.
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
Expand Down Expand Up @@ -95,15 +99,16 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
0, HEIGHT - 120, WIDTH, 30, generalDisplayArea, NULL, hInstance, NULL);
}

Spinner spinner = { 0 };
spinner.x = 100;
spinner.y = 123;
spinner.step = 1;
spinner.labelPtr = L"CPS";
spinner.labelSize = 0;
spinner.rangeMin = 1;
spinner.rangeMax = 80;
spinnerHWD = CreateSpinner(generalDisplayArea, hInstance, spinner);
Spinner cpsSpinner = { 0 };
cpsSpinner.x = 100;
cpsSpinner.y = 123;
cpsSpinner.step = 1;
cpsSpinner.labelPtr = L"CPS";
cpsSpinner.labelSize = 0;
cpsSpinner.rangeMin = 1;
cpsSpinner.rangeMax = 80;
cpsSpinner.defaultValue = L"2";
cpsSpinnerHWD = CreateSpinner(generalDisplayArea, hInstance, cpsSpinner);


/*
Expand All @@ -118,6 +123,20 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
SendMessage(startStopHotKey, HKM_SETHOTKEY, MAKEWORD(VK_F1, 0), 0);
RegisterHotKey(windowHandle, 0, MOD_NOREPEAT, VK_F1);

HWND checkbox = CreateWindow(WC_BUTTON, L"Timed Auto Click", WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
10, 70, 130, 20, settingsDisplayArea, SETTINGS_TIMED_CHECK_BOX, hInstance, NULL);
Spinner timedAutoClickSpinner = { 0 };
timedAutoClickSpinner.x = 10;
timedAutoClickSpinner.y = 100;
timedAutoClickSpinner.step = 1;
timedAutoClickSpinner.labelPtr = L"Seconds";
timedAutoClickSpinner.labelSize = 0;
timedAutoClickSpinner.rangeMin = 1;
timedAutoClickSpinner.rangeMax = 20;
timedAutoClickSpinner.defaultValue = L"5";
timedAutoSpinnerHWD = CreateSpinner(settingsDisplayArea, hInstance, timedAutoClickSpinner);
EnableWindow(timedAutoSpinnerHWD, FALSE);
EnableWindow((HWND)SendMessage(timedAutoSpinnerHWD, UDM_GETBUDDY, NULL, NULL), FALSE);

/*
===============
Expand Down Expand Up @@ -154,6 +173,22 @@ LRESULT CALLBACK SettingsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam
RegisterHotKey(mainWindowHandle, 0, HIBYTE(result), LOBYTE(result));
}
}
else if (cmd == BN_CLICKED) {
int id = LOWORD(wParam);
// Handle the check click for the timed checkbox.
if (id == SETTINGS_TIMED_CHECK_BOX) {
if (IsDlgButtonChecked(settingsDisplayArea, SETTINGS_TIMED_CHECK_BOX)) {
CheckDlgButton(settingsDisplayArea, SETTINGS_TIMED_CHECK_BOX, BST_UNCHECKED);
EnableWindow(timedAutoSpinnerHWD, FALSE);
EnableWindow((HWND)SendMessage(timedAutoSpinnerHWD, UDM_GETBUDDY, NULL, NULL), FALSE);
}
else {
CheckDlgButton(settingsDisplayArea, SETTINGS_TIMED_CHECK_BOX, BST_CHECKED);
EnableWindow(timedAutoSpinnerHWD, TRUE);
EnableWindow((HWND)SendMessage(timedAutoSpinnerHWD, UDM_GETBUDDY, NULL, NULL), TRUE);
}
}
}
}
break;
default:
Expand Down Expand Up @@ -210,7 +245,8 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// If the timmer is not running, trigger it.
if (autoClickerTimer == NULL) {
int pos = SendMessage(spinnerHWD, UDM_GETPOS32, NULL, NULL);
int pos = SendMessage(cpsSpinnerHWD, UDM_GETPOS32, NULL, NULL);
startClickerTime = time(NULL);
autoClickerTimer = SetTimer(hwnd, 1001, (1000 / pos), (TIMERPROC)NULL);
}
// Else, kill it.
Expand All @@ -232,6 +268,12 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
inputs[1].type = INPUT_MOUSE;
inputs[1].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTUP;
SendInput(2, &inputs, sizeof(INPUT));

// If timer mode is enabled, shut off the timer if over time.
if (IsDlgButtonChecked(settingsDisplayArea, SETTINGS_TIMED_CHECK_BOX) && time(NULL) - startClickerTime >= SendMessage(timedAutoSpinnerHWD, UDM_GETPOS32, NULL, NULL)) {
KillTimer(hwnd, autoClickerTimer);
autoClickerTimer = NULL;
}
}
break;
}
Expand Down
4 changes: 2 additions & 2 deletions AutoClickerDL/General.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ HWND CreateTabDisplayArea(HWND parent, HINSTANCE hInstance, LPCWSTR className, i
@returns The handle to the UPDOWN control.
*/
HWND CreateSpinner(HWND parent, HINSTANCE hInstance, Spinner spinner) {
HWND cpsLabel = CreateWindow(WC_STATIC, spinner.labelPtr, WS_VISIBLE | WS_CHILD | SS_LEFT, spinner.x + 64, spinner.y, 40, 20, parent, NULL, hInstance, NULL);
HWND cpsLabel = CreateWindow(WC_STATIC, spinner.labelPtr, WS_VISIBLE | WS_CHILD | SS_LEFT, spinner.x + 64, spinner.y, 60, 20, parent, NULL, hInstance, NULL);
HWND spinnerUpDown = CreateWindow(UPDOWN_CLASS, L"F", WS_VISIBLE | WS_CHILD | UDS_ARROWKEYS | UDS_SETBUDDYINT | UDS_ALIGNRIGHT,
0, 0, 0, 0, parent, NULL, hInstance, NULL);
HWND spinnerEdit = CreateWindow(WC_EDIT, L"2", WS_VISIBLE | WS_CHILD, spinner.x, spinner.y, 60, 20, parent, NULL, hInstance, NULL);
HWND spinnerEdit = CreateWindow(WC_EDIT, spinner.defaultValue, WS_VISIBLE | WS_CHILD, spinner.x, spinner.y, 60, 20, parent, NULL, hInstance, NULL);
// Set the buddy of the spinner.
SendMessage(spinnerUpDown, UDM_SETBUDDY, spinnerEdit, NULL);
UDACCEL spinnerValueChange = { 0 };
Expand Down
4 changes: 3 additions & 1 deletion AutoClickerDL/General.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ typedef struct {
int step;
LPCWSTR labelPtr;
int labelSize;
LPCWSTR defaultValue;
} Spinner;

HWND CreateTabDisplayArea(HWND parent, HINSTANCE hInstance, LPCWSTR className, int width, int height, WNDPROC procCallback);
HWND CreateSpinner(HWND parent, HINSTANCE hInstance, Spinner spinner);
HWND CreateSpinner(HWND parent, HINSTANCE hInstance, Spinner spinner);
HWND CreateCheckBox(HWND parent, HINSTANCE hInstance, LPCWSTR text, int x, int y, int width, int height, WNDPROC procCallback);

0 comments on commit f51c327

Please sign in to comment.