Windows控制台中的C ++键输入

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

我目前正在Windows中开发各种控制台游戏,使用 cin 的常规输入无法使用。

我如何(以简单的方式只使用MSVC中提供的标准窗口库):

  • 使程序等待(特定?)键按下并返回键ID(必须对所有键(包括箭头键)起作用)

  • p>在实时游戏期间检查用户的最后一次按下的键,以及自上次检查后是否按下任何键。

如果您可以为您的解决方案包括一个简短的示例程序,它真的会有帮助。

解决方案

使用标准C运行时。您将需要使用某些功能,如Win32函数 GetAsyncKeyState 。

I'm currently developing various console games in Windows that won't really work using regular input via cin.

How can I (In a simple way using only standard windows libraries available in MSVC):

  • Make the program wait for a (specific?) key press and return the key ID (It would have to work for all keys including the arrow keys)

  • During a real-time game check for the last pressed key of the user and if there was any key pressed since the last check.

It would really help if you could include a short example program for your solution

解决方案

AFAIK you can't do it using the standard C runtime. You will need to use something such as the Win32 function GetAsyncKeyState.

更多推荐

Windows控制台中的C ++键输入

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

发布评论

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

>www.elefans.com

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