Question

Is it possible to simulate mouse's move in PHP ? By that I mean to do something like :

$mouse->moveToCoordinate($x,$Y); // will move the screen to to the coordinate $X, $Y of the screen
$mouse->moveVector($x,$Y); // will move from the current point to the (current X + $X, current Y + $Y); 
$mouse->click(); // will simulate a mouse click on the screen.

This should be usable, even if no browser is open (so cannot use the classic browser-side javascript solution).

Was it helpful?

Solution

Just as an exercise. It might be possible to write standalone desktop PHP app that has access to user pointer. For that you have to use bindings such as http://gtk.php.net/ (there were Qt bindings some time ago, but project seems to be dead). And even that it might be hard. PHP-GTK is not well documented at this moment.

OTHER TIPS

PHP is a server side scripting language and cannot do that. You should do that by Javascript. It's possible to do that from PHP (write needed Javascript in PHP and send to client). The most real-time solution is using AJAX but you still suffering round-trip lags depending on client speed.

1 - use exec() and : Simulate mouse movement in Ubuntu . Basically, use any other language, compile it if needed, and use the executable with argument throughout command line.

2 - PHP-QT might do the trick

| IT IS POSSIBLE !!! |

People have suggested to use another language (javascript), but for this problem, it's not possible to use a browser. So other languages will do the trick.

Thanks for your message though, and if anybody have other solutions, I'd be interested to know them.

+1 To everything that was said before.

I'll add that more details on the goal is needed. Depending on what you really want (A click to do what ? On what ? etc...), you can still use cURL to reach a page, parsing it and following to the link you want (if that's a link you want to click...), entering a whole form and submiting it, etc... You can access to the html code and save it in a file on your server (if that's what you need.) etc... etc...

Anyway, as everyone said, PHP is server-side and, even as CLI, you need to have a server on your localhost and that will just execute a PHP script, PHP that don't have access to mouse/mouse movement etc without a client-side language like javascript.

IMHO I think your going about whatever it is your trying to do in the wrong way. There is no way to control the users mouse unless your using some sort of remote desktop app as that would be a security issue. That said I could take a guess as some possible things you could do

  1. set focus on an object using javascript
  2. click something using javascript 3 write and applescript (if on a mac) to click something in the finder or automate a process

hth

EDIT is should also be noted that if you use applescript stuidio you have access to objective c which would let you write code to change the mouse position. but I don't recommend it the user should control the mouse and nothing else should

It's not so hard. Look example.

You can easily edit it and send AJAX HTTP request for x,y positions and return xstart->x , ystart->y.

Hard part is make object to avoid other objects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top