atatusoft-ltd/php-key-listener
最新稳定版本:0.2.1
Composer 安装命令:
composer require atatusoft-ltd/php-key-listener
包简介
A PHP based API to capture key presses from the terminal.
关键字:
README 文档
README
PHP based command line key listener.

This library provides an API to capture keys from the terminal. It currently supports latin-basic range of characters such as direction keys, function keys (F*), enter, space, insert, delete, backspace, escape, a-z, etc.
Installation
You can either download this library as a zip, or simply install it via composer:
composer require atatusoft-ltd/php-key-listener
Limitations
This package only works on UNIX/Linux based systems since the Windows PHP version doesn't not support the readline extension.
Example
Capture all keys
use \Atatusoft\PhpKeyListener\Events\KeyPressEvent; use \Atatusoft\PhpKeyListener\Environment\Detector; $detect = new Detector(); $listener = $detect->getListenerInstance(); $eventDispatcher = $listener->getEventDispatcher(); $eventDispatcher->addListener('key:press', function(KeyPressEvent $event) { echo $event->getKey(), PHP_EOL; }); $eventDispatcher->addListener('key:enter', function(KeyPressEvent $event) use ($eventDispatcher) { echo 'Key "', $event->getKey(), '" was pressed. Quitting listener.', PHP_EOL; // notify the listener to stop $eventDispatcher->dispatch('key:stop:listening'); }); $listener->start();
License
Licensed under MIT.
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-09