This project was made for fun, feel free to improve it :)
Under your project's folder type:
$ composer require nawarian/php-bot dev-master
<?php
require_once 'vendor/autoload.php';
Then you are ready to go :D
PHPBot works directly with X11, using xdotool
to
send commands. Further versions could add support to
other devices as well.
Make it independent from xdotool
would also be nice,
projects like https://github.com/moriyoshi/php-Xlib
are
a great shot! But still excludes MS Windows implementations...
PHPBot now can work with Windows NT platforms too.
Is important to notice that: it uses compiled python files that
access the User32.dll API. Because of that, some antivirus software
might mark the files under ext/pyautogui/bin/dest
folder as threads.
Also: the command pipeline funcionality has shown some bugs.
All commands alone returns a React\Promise\Promise
You must have a React\EventLoop\LoopInterface object
:
$loop = React\EventLoop\Factory::create();
// Our code goes here!
$loop->run();
As a command
you can think of a interaction command, like a
button pressing, mouse moving ou clicking...
Notice that all commands will only run if:
- The
start()
method is called - Is in a command pipeline
Is important to also notice that command pipelines will start by the moment you create it.
$dm = PHPBot\DesktopManager\Factory::create($loop);
$dm->keyboard()->type('Soooo cool!')->start()->then(function() {
// Remember, every command returns a Promise!
echo 'Just wrote it, dude! ;)';
});
$dm = PHPBot\DesktopManager\Factory::create($loop);
$dm->pointer()->moveTo(0, 0)->start()->then(function() {
// Remember, every command returns a Promise!
echo 'Guess where your mouse pointer is!';
});
$dm = PHPBot\DesktopManager\Factory::create($loop);
$dm->createCommandPipeline(
$dm->keyboard()->type('Soooo cool!'), // 1
$dm->keyboard()->sendKey(Keys::ENTER()), // 2
$dm->pointer()->moveTo(200, 200), // 3
$dm->pointer()->click(MouseButtons::LEFT()) // 4
)
->start()
->then(function() {
// This also returns a Promise, resolved when it all finishes
echo 'DONE!';
});
1, 2, 3 and 4 will execute at this exaclty order!
Thank you :)