php / php/php-src

Capture keypresses on Windows

未关闭
#12,939 3 条评论 29 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Category: Streams Feature OS: Windows
主要语言
C
星标
40.4k
派生
8.2k
平均合并
2 天 15 小时
30 天内合并 PR
103

描述

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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先查看 bugs.php.net/bug.php?id=34972 中的历史讨论,以及 php-src 中现有的终端输入处理。确定适当的 Windows 入口点,以及在受支持的操作系统上捕获单次按键应如何工作。当有一种有文档记录且经过测试的跨平台方式可以读取按键而无需 Enter 时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
c, php
领域
cli, operating-systems
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。