实时键盘输入到控制台(在Windows中)? [英] Real-time keyboard input to console (in Windows)?

查看:320
本文介绍了实时键盘输入到控制台(在Windows中)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个双向链表类,其中我想在用户键入它们时向列表中添加字符,或者每当用户按下退格键时删除列表中的最后一个节点,同时在控制台中显示结果-time。

I have a doubly-linked list class, where I want to add characters to the list as the user types them, or removes the last node in the list each time the user presses backspace, whilst displaying the results in console in real-time.

我将使用什么功能来拦截单个键盘输入,并实时显示到控制台?所以结果如下:

What functions would I use to intercept individual keyboard input, and display it in real-time to the console? So the following results:

用户开始输入:


Typ_

Typ_

用户停止输入:


Typing this on screen_

用户按backspace 5次:

User presses backspace 5 times:


在s_

Typing this on s_

特定的操作系统是windows(更具体地说是vista)。

Particular OS is windows (vista, more specifically).

在windows.h下面的一个旁注GetAsyncKeyState可能是用于键盘输入,但是控制台的实时显示问题仍然存在。

As a side-note GetAsyncKeyState under windows.h appears to perhaps be for keyboard input, however the issue of real-time display of the console remains.

推荐答案

你会惊讶,但这段代码会做你想要的:

You will be surprised, but this code will do what you want:

/* getchar example : typewriter */
#include <stdio.h>

int main ()
{
  char c;
  puts ("Enter text. Include a dot ('.') in a sentence to exit:");
  do {
    c=getchar();
    putchar (c);
  } while (c != '.');
  return 0;
}

这篇关于实时键盘输入到控制台(在Windows中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆