在密钥到达控制台之前将其捕获 [英] trapping a key before it gets to the Console

查看:62
本文介绍了在密钥到达控制台之前将其捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置:

.net中的控制台程序

A Console program, in .net

我在循环中使用readkey,它将重写为屏幕上的同一行(Console.setCursorPosition)

I am using readkey in a loop, which rewrites to the same line on the screen (Console.setCursorPosition)

但是,如果我键入Enter,则控制台会将文本向上推,这是通常的命令行行为.

however, if I type Enter, the Console pushes the text upwards, which is the usual command line behaviour.

问题:

是否可以捕获一个按键(即Enter),以便我的程序可以获取该按键,但控制台不能?

Is it possible to trap a key press (that Enter), so that my program will get the key, but the Console does not?

环境是Linux,带有Mono(并且该程序应该是跨平台的).因此低级别的Windows驱动程序拦截是不可行的.

The environment is Linux, with Mono (and the program is supposed to be cross platform). so low level windows driver intercepting is not an option.

PS:我知道清除并重新绘制所有内容的方法.我想知道我的问题是否可能.

PS: I know the method of clearing and redrawing everything. I would like to know if my question is possible.

感谢您提供任何信息

推荐答案

Console.ReadKey(true) 应该读取密钥,但不显示密钥.

Console.ReadKey(true) should read the key but not show it.

这篇关于在密钥到达控制台之前将其捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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