he426100 / php-windows
There is no license information available for the latest version (dev-main) of this package.
dev-main
2024-05-30 08:02 UTC
Requires
- ext-ffi: *
- ffi/proxy: ^1.0
- local/com: ^1.0
- local/driver-win32: ^1.0
Requires (Dev)
- pestphp/pest: ^2.28
- phpstan/phpstan: ^1.9
- psy/psysh: ^0.12.0
Suggests
- skoro/tkui: Required to use Tk.
Replaces
- he426100/php-windows-helper: *
- he426100/phpautogui: *
- he426100/phpgetwindow: *
- he426100/phpmsgbox: *
This package is auto-updated.
Last update: 2025-03-01 00:41:19 UTC
README
简介
基于php ffi,移植pyautogui
、pymsgbox
、pygetwindow
示例
- phpautogui notepad
<?php require __DIR__ . '/../vendor/autoload.php'; use He426100\phpautogui\phpautogui; use He426100\phpautogui\platforms\windows\windows; $auto = new phpautogui(new windows); $auto->press('win'); usleep(0.2 * 1000_000); $auto->typewrite('notepad.exe', 0.1); usleep(0.2 * 1000_000); $auto->press('enter'); usleep(2 * 1000_000); $auto->typewrite('PHP is the best language.', 0.1);
- phpautogui mouse
<?php require __DIR__ . '/../vendor/autoload.php'; use He426100\phpautogui\phpautogui; use He426100\phpautogui\platforms\windows\windows; $auto = new phpautogui(new windows); $size = $auto->size(); $position = $auto->position(); echo 'currentX: ' . $position[0], ', currentY: ' . $position[1], ', width: ' . $size[0], ', height: ' . $size[1], PHP_EOL; $s = microtime(true); $central = [$size[0] / 2, $size[1] / 2]; $auto->moveTo($central[0], $central[1], 0.5); assert($auto->position() == $central); echo 'moved to (', $central[0], ', ', $central[1], '), used ' . (microtime(true) - $s) . ' s', PHP_EOL;
- phpmsgbox
<?php require __DIR__ . '/../vendor/autoload.php'; use He426100\phpmsgbox\phpmsgbox; use He426100\phpmsgbox\platforms\windows\windows; $msg = new phpmsgbox(new windows); $msg->alert('php是最好的语言。', '温馨提示'); echo $msg->confirm('php是最好的语言。', '温馨提示'), PHP_EOL;
- phpgetwindow
<?php
require __DIR__ . '/../vendor/autoload.php';
use He426100\phpgetwindow\phpgetwindow;
use He426100\phpgetwindow\platforms\windows\windows;
$native = new windows;
$window = new phpgetwindow($native);
echo "活动窗口标题: " . $window->getActiveWindowTitle() . "\n";
echo "所有窗口标题:\n";
print_r($window->getAllTitles());
如何写cdef
- 数据类型
- windows-data-types
- rect
- point
- 用
vs_BuildTools
下载windows sdk
后在C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\um
中找到对应的头文件,比如winint.h
- 函数接口
- 回调函数
- EnumWindows.WNDENUMPROC
原版定义,见 nf-winuser-EnumWindowsBOOL EnumWindows( [in] WNDENUMPROC lpEnumFunc, [in] LPARAM lParam ); BOOL CALLBACK EnumWindowsProc( _In_ HWND hwnd, _In_ LPARAM lParam );
在ffi中写法是BOOL EnumWindows(void (*)(HWND, LPARAM), LPARAM);
在PHP FFI中,由于不能直接声明一个函数指针类型,因此通常使用void (*)(HWND, LPARAM)来表示这样一个接受特定参数类型的函数指针。这里的void表示回调函数没有返回值(在C中通常是BOOL或者WNDENUMPROC定义的返回类型),圆括号内的(HWND, LPARAM)则是指明回调函数需要接受的参数类型。(来自千问)