Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if mouse click is legit or automated?

Tags:

c++

vb.net

How to know if a mouse click is simulated or not? When mouse click send by a program or real mouse device

... I'm programming a system detection for a game to avoid bots, autoclicks,etc that only accept legit mouse clicks

like image 344
PEXINA Avatar asked Feb 23 '11 13:02

PEXINA


People also ask

How do I track my mouse movement?

A mouse recorder is a tool that records mouse movements on a website. So when someone visits your site, a mouse recorder records all their interactions on your site – mouse movements as well as clicks.

How does a mouse click work?

A mouse click is the action of pressing (i.e. 'clicking', an onomatopoeia) a button to trigger an action, usually in the context of a graphical user interface (GUI). “Clicking” an onscreen button is accomplished by pressing on the real mouse button while the pointer is placed over the onscreen button's icon.


4 Answers

This depends a bit on the kind of application you are writing, but if you can, I would watch the cursor movement, not the clicks. Human mouse movement has non-uniform speeds, reaction times, imprecisions (clicks on different coordinates of your buttons, etc...).

Also, you can defend a gui against bots by randomly requiring an interaction that is hard to script. For example: If scripts depend upon buttons being always in the same position, I would make sure that, while trying to remain intuitive, the dialog should pop up in slightly different positions every time.

Otherwise: There is no way to detect if the mouse is a real one or a really well simulated one. The Windows HID/MacOS/Linux driver layer abstracts away the distinction between Mice, TrackPens, TrackBalls, draw-pads, touch screens... and of course script-mice...

like image 163
AndreasT Avatar answered Nov 11 '22 04:11

AndreasT


Although the blog post itself is about a different issue, I refer you to Raymond Chen's excellent Old New Thing. In this specific blog post he talks about the validity of message parameters going into an application, but also makes the point that:

There's no point discussing the possibility that the sender of the message is playing tricks and lying to you because (1) your program should just go along with the ruse and respond to fake menu messages as if they were real menu messages, because (2) there's no way to tell that you're being lied to anyway. To detect lying, you'd have to be able to read into the mindset of the programmer who sent you the message.

Essentially the argument is that you should respond to mouse clicks as mouse clicks, regardless of how those clicks were generated.

like image 44
icabod Avatar answered Nov 11 '22 05:11

icabod


Is mouse keys simulated mouse input or legit? The point of simulating mouse input is to make them look exactly like real mouse input. If the simulation is doing its job, then your job is impossible. Sorry, that's the blessing & curse of software for you. Here are some more imperfect ideas:

  1. Use GetKeyboardState and verify that the button states are correct. If the message faker is using PostMessage, they will likely not be setting keyboard state and this would indicate fakery.
  2. If you are targeting known applications that are doing the input simulation, detect them and complain. This is not perfect at all for many reasons.
  3. Fuzzy logic, as many other people have suggested.

You need to be creative and figure out the difference between a simulated event and a real one to you, as there is no generalized answer.

like image 38
tenfour Avatar answered Nov 11 '22 05:11

tenfour


It can't be done (reliably (with software alone anyway))

I've used WIN32API calls to read pixels/manipulate the mouse/send keystrokes to automate large portions of video games and other repetitive tasks. You could write a lot of code to analyze the input, but equally smart developers are just going to modify their code to match.

When I first try to automate a mouse click, that's all I'll do. Send a mouse click. And most of the time it works. You might have code that tracks the mouse movement and the entire stack of mouse events that would fire along with a legitimate click and say, 'That wasn't real - we ignore it' but nothing stops the developer from also implementing mouse movements.

The mouse events are more complex than keypresses; but it's essentially the same idea. If you write code that monitors the time between keypresses and determine that I'm sending the '2' key to your application in EXACTLY 250ms intervals, you might decide I'm a bot. But, all I'll do is modify my code to send the keystroke in 250ms + a random value between -25 and 25 ms.

It's a never-ending game of cat and mouse. The best solution is to make tasks non-trivial so simple forms of automation aren't applicable.

like image 40
Rob P. Avatar answered Nov 11 '22 03:11

Rob P.