PHP Windows的桌面自動化
最新內(nèi)容-> GITHUB
composer
composer require kingbes/phprobot
php >=8.1.0
拓展 FFI
系統(tǒng) 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
{}
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 整數(shù)鍵碼值
* @return boolean
*/
public function isKeyPressed(int $key): bool
{}
/**
* 點擊鍵盤某鍵 function
*
* @param integer $key 整數(shù)鍵碼值
* @return void
*/
public function onClickKey(int $key): void
{}
獲取當前鼠標位置
// 引入
use KingBes\PhpRobot\Mouse;
// 實例
$Mouse = new Mouse();
// 獲取鼠標當前指針位置
$pos = $Mouse->mouse_pos();
var_dump($pos);
監(jiān)聽鍵盤A鍵
use KingBes\PhpRobot\Keyboard;
$Keyboard = new Keyboard;
while (true) {
if ($Keyboard->isKeyPressed(65)) {
echo "點擊了鍵盤A \n";
}
usleep(100); // 減輕負擔
}
按下鍵盤A鍵
use KingBes\PhpRobot\Keyboard;
$Keyboard = new Keyboard;
sleep(5); //延遲5秒
$Keyboard->onClickKey(65)
在 Windows 操作系統(tǒng)中,鍵盤上的一些按鍵對應著特定的整數(shù)鍵碼值(keyCode)。以下是一些常見的 win 鍵盤按鍵及其對應的十進制數(shù)字:
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
:57Backspace
: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
:1440
:961
:972
:983
:994
:1005
:1016
:1027
:1038
:1049
:105*
:106+
:107Enter
:108-
:109.
:110/
:111Left Windows 鍵
:91Right Windows 鍵
:92Applications 鍵
(右 Ctrl 左邊鍵,點擊相當于點擊鼠標右鍵,會彈出快捷菜單):93
我敲,之前一直用python的pyautoui,沒想到PHP不但可以做桌面端,還可以做自動化?YYDS