返回pressed键输入不确认 [英] Return pressed key without enter for confirmation
问题描述
我搜索了一会儿发现在Windows系统中的功能在C语言编程使用,以确定哪些关键是pressed,而无需ENTER键确认。
I've searched for a while to find a function in Windows systems to use in C programming, to determine which key was pressed, without requiring the 'enter' key for confirmation.
我发现的kbhit()
,但这只是回报率的关键preSS阳性,0虽然没有键盘preSS。我想在一个功能相同的行为,但我返回键的ASCII code。
I've found kbhit()
, but this only returns positive on key press, and 0 while no key-press. I'd like the same behavior on a function, but returning my key's ASCII code.
原因是,我想建立一些控件,在一个基于控制台的游戏,在那里我需要箭头浏览播放器。 'A'会提出我的观点向左,'D'的权利。
The reason is that I want to build some controls, on a console-based game, where I need arrows to navigate the player. 'A' would move my point left, 'D' right.
在这个时刻,我需要preSS'a'和'进','D'和'进入,用简单的 scanf函数(%C)
,并且将是很好,如果控制台将只有pressing一个字母,而不是对每一个动作一个+输入反应。
At this moment, I need to press 'a' and 'enter,' 'd' and 'enter,' with the simple scanf("%c")
, and would be nice if the console would react only if pressing a letter instead of a+enter on every movement.
推荐答案
看看这个:
char ch;
ch = getch();
if(ch == 's') printf("you pressed s \n");
这篇关于返回pressed键输入不确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!