simulate mouse move in php?
⚠ In this question, PHP is used in an unusual way. It is not used as a server side language ("no browser is open"). It is intended to be run on my own computer, simulating mouse move on my computer.
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).
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.
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.
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.
+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
- set focus on an object using javascript
- 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.
精彩评论