PHP code example of atatusoft-ltd / php-key-listener
1. Go to this page and download the library: Download atatusoft-ltd/php-key-listener 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/ */
atatusoft-ltd / php-key-listener example snippets
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();
composer