DOS 中 getch() 函数的退格和删除问题
我在 Windows 平台、Intel x86 架构上使用 Turbo C 编译器。
在我的程序中,我正在扫描键盘上的用户输入。它是一个登录密码程序,接收用户名和密码作为用户输入。
对于我使用 getchar() 的用户名,在输入用户名时,如果用户按键盘上的退格键,前一个字符将被删除,它本身,我的意思是我不需要编写任何显式代码做这个。
但对于密码,我使用 getch() 并对应于每次击键,我在屏幕上显示一个 *。在这种情况下,如果用户按下键盘上的退格键,它不会删除前一个字符,而是将其视为另一个击键,并在屏幕上显示与其相对应的*。
我尝试了bios.h中的bioskey,尝试使用\b来解决,但没有成功。
任何建议或解决方法......???
I am using the Turbo C compiler on a Windows platform, Intel x86 architecture.
In my program I am scanning user input from the keyboard. It is a login password program that takes in username and password as user inputs.
For the username I am using getchar(), where while entering the username if the user presses the backspace key, on the keyboard, the previous character gets deleted, on it's own, I mean I don't need to write any explicit code to do this.
But for the password I am using getch() and corresponding to every keystroke I am displaying a * on the screen. In this case if user presses the backspace key on the keyboard, it does not delete the previous character, but rather takes it as another key stroke and displays a * corresponding to it on the screen.
I tried out bioskey from bios.h, tried using \b to work around, none worked.
Any suggestions or workarounds....????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然。自己跟踪角色。如果您的程序接收退格键并显示 *,则检查该字符并备份一个空格。备份一个空格后,打印一个空格以删除*,然后再次备份。
Sure. Keep track of the characters for yourself. If your program is receiving the backspace so that it displays a *, then check for that character and back up one space. After backing up one space, print a space to erase the *, then back up again.
这是获取密码的代码:
我希望这会对您有所帮助.. :-D:-D ..
Here is the code to get the passowrd:
I hope that this will help you.. :-D:-D..