Tag: getch

在Linux上使用kbhit()和getch()

在Windows上,我有以下代码来查找input而不中断循环: #include <conio.h> #include <Windows.h> #include <iostream> int main() { while (true) { if (_kbhit()) { if (_getch() == 'g') { std::cout << "You pressed G" << std::endl; } } Sleep(500); std::cout << "Running" << std::endl; } } 但是,看到没有conio.h ,在Linux上实现这个同样的事情最简单的方法是什么?

如何在Linux中实现C的getch()函数?

在TurboC ++中,我可以使用conio.h的getch()函数。 但在Linux中,gcc不提供conio.h 。 我怎样才能得到getch()的function?

getch和箭头代码

我正在编写一个使用getch()扫描箭头键的程序。 我的代码到目前为止是: switch(getch()) { case 65: // key up break; case 66: // key down break; case 67: // key right break; case 68: // key left break; } 问题是当我按'A' , 'B' , 'C'或'D' ,代码也会被执行,因为65是'A'的十进制代码等等。 有没有办法检查一个箭头键没有打电话给别人? 谢谢!

如何获得一个单一的字符,而无需按下input?

怎样才能从terminal用Rubyinput一个单一的键盘字符? 我尝试了Curses::getch ,但那对我来说并不是真的。

如何让密码回显为星号

我想弄清楚如何提示input密码,并让用户input回显为星号( ******** ) 所以最近,我接手了创build一个远程服务器的项目,该服务器可以使用Python中的套接字模块进行连接。 它还没有完成,因为我正在使控制台用于连接到服务器的过程。 我正在尝试做一个login窗口提示用户input他们的用户名和密码,虽然当input密码,我正在寻找星号打印,如普通密码input(即 – Sekr3t echo'd为:* * * * * *)。 经过几天的研究,我差不多完成了,但还有一个最后的错误让我疯狂(我完全无法解决它)。 注 – 我知道有一个getpass模块可以用来取代这个,更容易,但没有echo'd不是我正在寻找。 这里是我到目前为止的密码login代码,我不明白为什么它不回显星号: import msvcrt import sys def login(prompt = '> '): write = sys.stdout.write for x in prompt: msvcrt.putch(x) passw = "" while 1: x = msvcrt.getch() if x == '\r' or x == '\n': break if x […]