C++ Detect when user presses arrow key(C ++检测用户何时按下箭头键)
问题描述
我在检测 C++ 控制台应用程序中的箭头键按下时遇到了问题.我已经尝试了在这里和其他教程网站上找到的所有内容,但是每当我按下箭头时,它们都会给我同样的东西:
I have been having a problem with detecting arrow key presses in my C++ console application. I have tried everything I have found, both here and on other tutorial sites, but all of them give me the same thing whenever I press the arrow:
这是我尝试过的所有检测按键的方法,结果都是一样的.这些是我的代码中仅剩的两个,其他我尝试删除而不是注释掉.
Here are all the methods of detecting the key press that I have tried, all ending up the same way. These are the only two left in my code, the others I attempted I deleted instead of commenting out.
方法一:
方法二:
我的代码中是否有一些错误让我回到我的主要方法,或者它是否跳过了一些代码?有没有更快的方法来做到这一点?我几乎 100% 确定我的其他代码与这个问题没有任何关系,因为我将代码与程序的任何其他方面隔离开来,并且我一直遇到同样的问题.
Is there some error in my code which made me go back to my main method, or did it skip over some code? Is there a faster way to do this? I'm almost 100% sure that my other code doesn't have anything to do with this problem, because I isolated the code from be dependent on any other aspect of the program, and I kept having the same problem.
再次,我尝试了所有我能找到的获取箭头键的方法,但我一直遇到同样的问题.如果重要的话,我使用的是 Windows 8 Samsung ATIV Smart PC 并使用键盘底座.
Again, I tried every method of getting the arrow key press that I could find, and I keep getting the same problem. If it matters, I'm on a Windows 8 Samsung ATIV Smart PC and using the keyboard dock.
提前感谢您的帮助.
推荐答案
输出如下:
检测到方向键按下!
这篇关于C ++检测用户何时按下箭头键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!