检查是否在Windows控制台中按下了键

编程入门 行业动态 更新时间:2024-10-26 22:17:47
本文介绍了检查是否在Windows控制台中按下了键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复: C ++控制台键盘事件

如果要按下某个键,我希望Windows控制台程序执行某些操作,像

I want a Windows console program to do something if a certain key is pressed down, something like

while(1) { .... if(the key 'o' is pressed down) .... }

但我不知道要在 if 语句中添加什么.如何检查键"o"是否按下?

but I don't know what to put in the if statement. How do I check if the key 'o' is pressed down?

我正在使用Windows 7 64位和Visual Studio Professional 2008.

I'm using Windows 7 64-bit and Visual Studio Professional 2008.

推荐答案

您应该在应用程序中注册按键事件(假设这是Windows GUI应用程序),而不是忙于查询按键,并检查按键您感兴趣.

Rather than busy-polling for a keypress, you should register for key events in your application (assuming this is a Windows GUI app), and check for the keys you're interested in.

如果您实际上是在制作控制台应用程序,请参见此处: C ++控制台键盘事件

If you are actually making a console app, see here: C++ console keyboard events

更多推荐

检查是否在Windows控制台中按下了键

本文发布于:2023-11-06 09:40:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563339.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制台   按下   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!