PHP code example of kingbes / phprobot

1. Go to this page and download the library: Download kingbes/phprobot library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kingbes / phprobot example snippets


use KingBes\PhpRobot\Mouse;

$Mouse = new Mouse();

/**
 * 鼠标指针位置 function
 *
 * @return array
 */
public function mouse_pos(): array
{}

/**
 * 鼠标单击 function
 *
 * @param string $button left right middle
 * @return self
 */
public function mouse_click(string $button): self
{}

/**
 * 鼠标双击 function
 *
 * @param string $button left right middle
 * @return self
 */
public function mouse_double_click(string $button): self
{}

/**
 * 将鼠标(左)拖动到指定位置。 function
 *
 * @param integer $x
 * @param integer $y
 * @return self
 */
public function mouse_left_drag(int $x, int $y): self
{}

/**
 * 相对于当前位置拖动鼠标(左)。 function
 *
 * @param integer $offset_x
 * @param integer $offset_y
 * @return self
 */
public function mouse_drag_rel(int $offset_x, int $offset_y): self
{}

/**
 * 移动鼠标到 x y function
 *
 * @param integer $x
 * @param integer $y
 * @return self
 */
public function mouse_move_mouse(int $x, int $y): self
{}

/**
 * 相对于当前位置移动鼠标。 function
 *
 * @param integer $offset_x
 * @param integer $offset_y
 * @return self
 */
public function move_mouse_rel(int $offset_x, int $offset_y): self
{}

/**
 * 鼠标平滑移动指定位置 function
 *
 * @param integer $x
 * @param integer $y
 * @param integer $duration_ms 毫秒
 * @param string $tween 预览补间 参数请看下面 `预览补间` 说明
 * @return self
 */
public function move_mouse_smooth(int $x, int $y, int $duration_ms, string $tween): self
{}

/**
 * 当前平滑移动鼠标 function
 *
 * @param integer $offset_x
 * @param integer $offset_y
 * @param integer $duration_ms 毫秒
 * @param string $tween 预览补间 参数请看下面 `预览补间` 说明
 * @return self
 */
public function move_mouse_smooth_rel(int $offset_x, int $offset_y, int $duration_ms, string $tween): self
{}

/**
 * 鼠标按下 function
 *
 * @param string $button left right middle
 * @return self
 */
public function mouse_down(string $button): self
{}

/**
 * 鼠标弹起 function
 *
 * @param string $button left right middle
 * @return self
 */
public function mouse_up(string $button): self
{}

use KingBes\PhpRobot\Screen;

$Screen = new Screen();

/**
 * 获取屏幕指定位置的颜色rgb function
 *
 * @param integer $x
 * @param integer $y
 * @return array
 */
public function pixel_color(int $x, int $y): array
{}

/**
 * 获取屏幕大小 function
 *
 * @return array
 */
public function screen_size(): array
{}

use KingBes\PhpRobot\Keyboard;

$Keyboard = new Keyboard;

/**
 * 是否点击键盘某键 function
 *
 * @param integer $key 整数键码值
 * @return boolean
 */
public function isKeyPressed(int $key): bool
{}

/**
 * 点击键盘某键 function
 *
 * @param integer $key 整数键码值
 * @return void
 */
public function onClickKey(int $key): void
{}

/**
 * 按下键盘某键 function
 *
 * @param integer $key
 * @return self
 */
public function pressKey(int $key): self
{}

/**
 * 弹起键盘某键 function
 *
 * @param integer $key
 * @return self
 */
public function releaseKey(int $key): self
{}

// 引入
use KingBes\PhpRobot\Mouse;

// 实例
$Mouse = new Mouse();
// 获取鼠标当前指针位置
$pos = $Mouse->mouse_pos();

var_dump($pos);

// 引入
use KingBes\PhpRobot\Mouse;

sleep(3);// 等待
// 按下 左键
$Mouse->mouse_down("left");

sleep(3);// 等待
// 弹起 左键
$Mouse->mouse_up("left");

use KingBes\PhpRobot\Keyboard;

$Keyboard = new Keyboard;

while (true) {
    if ($Keyboard->isKeyPressed(65)) {
        echo "点击了键盘A \n";
    }
    usleep(100); // 减轻负担
}

use KingBes\PhpRobot\Keyboard;

$Keyboard = new Keyboard;

sleep(5); //延迟5秒

$Keyboard->onClickKey(65)

use KingBes\PhpRobot\Keyboard;

$Keyboard = new Keyboard;

sleep(3);// 等待
// 按下
$Keyboard->pressKey(65);

sleep(3);// 等待
// 弹起
$Keyboard->releaseKey(65);