2017 © Pedro Peláez
 

library phkey

A PHP based API to capture key presses from the terminal.

image

ignasbernotas/phkey

A PHP based API to capture key presses from the terminal.

  • Wednesday, April 20, 2016
  • by ignasbernotas
  • Repository
  • 3 Watchers
  • 2 Stars
  • 42 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 2 % Grown

The README.md

PHKey

PHP based command line key listener.

, (*1)

Example

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., (*2)

Installation

You can either download this library as a zip, or simply install it via composer:, (*3)

composer require ignasbernotas/phkey

Limitations

This package only works on UNIX/Linux based systems since the Windows PHP version doesn't not support the readline extension., (*4)

Example

Capture all keys
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();

License

Licensed under MIT., (*5)

The Versions

20/04 2016

dev-master

9999999-dev https://iber.lt

A PHP based API to capture key presses from the terminal.

  Sources   Download

MIT

The Requires

 

The Development Requires

cli keyboard keys key press

13/04 2016

0.1.1

0.1.1.0 https://iber.lt

A PHP based API to capture key presses from the terminal.

  Sources   Download

MIT

The Requires

 

The Development Requires

cli keyboard keys key press

02/02 2016

v0.1

0.1.0.0 https://iber.lt

A PHP based API to capture key presses from the terminal.

  Sources   Download

MIT

The Requires

 

The Development Requires

cli keyboard keys key press