PHP code example of ignasbernotas / phkey
1. Go to this page and download the library: Download ignasbernotas/phkey 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/ */
ignasbernotas / phkey example snippets
use \Iber\Phkey\Events\KeyPressEvent;
use \Iber\Phkey\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();