php / php/php-src

Capture keypresses on Windows

オープン
#12,939 コメント 3 件 リアクション 29 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Category: Streams Feature OS: Windows
主要言語
C
スター
40.4k
フォーク
8.1k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

Description

Some tutorials and packages show it is possible to capture and handle keypresses on terminals, but only available on *nix systems

The example below shows a commonly see implementation.

<?php

$stdin = fopen('php://stdin', 'r');
system('stty cbreak -echo');

stream_set_blocking($stdin, false);

while (1) {
    $keypress = fgets($stdin);
    if ($keypress) {
        echo 'Key pressed: ' . $keypress . PHP_EOL;
    }
}

EDIT:
This example captures keys presses in the open terminal, except: shift, alt, control, caps lock, meta and fn


This example above does not work on Windows.
The intention is to capture a single keypress, of course, without typing enter. This would make possible things like terminal games and many command line apps, working for any O.S.

This was discussed in the past here: https://bugs.php.net/bug.php?id=34972

image

CMB gave some hope this would be implemented, and so, not a bug at all.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず bugs.php.net/bug.php?id=34972 の過去の議論と、php-src における既存の端末入力処理を確認します。適切な Windows のエントリーポイントと、サポート対象のオペレーティングシステム全体で 1 回のキー押下を取得する際の動作を判断します。Enter を必要とせずにキーを読み取る、文書化およびテスト済みのクロスプラットフォームな方法があれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, php
領域
cli, operating-systems
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。