PHP Windows的桌面自动化
composer
composer require kingbes/phprobotphp >=8.1.0
拓展 FFI
系统 Windows
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);你可以在这里预览补间: https://easings.net/
linearease_in_quadease_out_quadease_in_out_quadease_in_cubicease_out_cubicease_in_out_cubicease_in_quartease_out_quartease_in_out_quartease_in_quintease_out_quintease_in_out_quintease_in_sineease_out_sineease_in_out_sineease_in_expoease_out_expoease_in_out_expoease_in_circease_out_circease_in_out_circease_in_elasticease_out_elasticease_in_out_elasticease_in_backease_out_backease_in_out_backease_in_bounceease_out_bounceease_in_out_bounce
在 Windows 操作系统中,键盘上的一些按键对应着特定的整数键码值(keyCode)。以下是一些常见的 win 键盘按键及其对应的十进制数字:
- 字母和数字键:
a:65b:66c:67d:68e:69f:70g:71h:72i:73j:74k:75l:76m:77n:78o:79p:80q:81r:82s:83t:84u:85v:86w:87x:88y:89z:900:481:492:503:514:525:536:547:558:569:57
- 控制键:
Backspace:8Tab:9Clear:12Enter:13Shift:16Control:17Alt:18Caps Lock:20Esc:27Spacebar:32Page Up:33Page Down:34End:35Home:36Left Arrow:37Up Arrow:38Right Arrow:39Down Arrow:40Insert:45Delete:46Num Lock:144
- 数字键盘上的键:
0:961:972:983:994:1005:1016:1027:1038:1049:105*:106+:107Enter:108-:109.:110/:111
- 其他键:
Left Windows 键:91Right Windows 键:92Applications 键(右 Ctrl 左边键,点击相当于点击鼠标右键,会弹出快捷菜单):93