first, you need a way to count how many clicks the player made. every time they click, you add +1 to a variable that stores the total.
then, you need to know when the counting started. so, when the first click happens, you mark the current time as the starting point.
every second (or periodically), you check how many clicks happened within that one-second window. that number is the cps — clicks per second.
if that number is too high, like 20 or 30 clicks per second, it’s very likely the person is using an autoclicker. then you can decide what to do: show a warning, block clicking, or just log it for analysis later.
when a second passes, you can reset the counter and start again, or use a smarter approach: store the timestamp of each click and remove the ones older than one second. this way, the cps keeps updating in real time without needing to reset.
I did this on my own site that also calculates CPS: https://day-apps.com/en/click-counter