使用Turbo C ++测试是否按下了键 [英] Test if key is pressed using Turbo C++
本文介绍了使用Turbo C ++测试是否按下了键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何使用Turbo C ++代码测试是否按下了按键移位,ctrl和alt.
I want to know how to test whether the key shift, ctrl and alt are pressed or not using Turbo C++ code.
推荐答案
检查0x40处的字节: 17-它包含DOS程序中的shift状态,alt状态和ctrl键状态-如果您使用的是Turbo C,我想您正在写.我不记得这些是什么了,所以您"按下各种contol/sh * t/alt键时,将不得不编写一个小程序来输出字节.
要访问此字节,您需要一个远指针:
unsigned char far * key_state_bye =(unsigned char far *)0x00400017;
我记不清具有const功能的Turbo C了,但是如果它可以使const值成功,我也可以使其设为const,以防止发生意外.
干杯,
Ash
Check the byte at 0x40:17 - it contains the shift state, alt state and ctrl key state in a DOS program - which I presume you''re writing if you''re using Turbo C. I can''t remember what the bits are so you''ll have to write a little program to output the byte there when you''ve pressed various contol/sh*t/alt keys.
To access this byte you need a far pointer:
unsigned char far *key_state_bye = (unsigned char far *)0x00400017;
I can''t remember how const capable Turbo C was but if it can manage to make the value const I''d make it const as well to prevent accidents.
Cheers,
Ash
您可以尝试使用kbhit()
函数(尽管我不确定是否会成功).为什么不使用更新的开发工具,例如Visual C++ Express Edition
(免费)?
:)
You may try thekbhit()
function (though I''m not sure it will make the trick). Why dont'' you use a more updated development tool, like, for instanceVisual C++ Express Edition
(it''s free)?
:)
抱歉,Ash和CP有点脱节. Turbo C plusplus 是21世纪的产品. (将其视为Borland C ++ Studio的"Express"版本.)如果使用的是VCL,则KeyDown事件会将ctrl/alt/shift状态作为参数.如果要编写控制台应用程序,请查看GetKeyState()和相关功能上的Turbo C ++帮助. (还有另一种方法,但是我已经忘记了...)
Sorry to say this, but Ash and CP are a little out of touch. Turbo Cplusplus is a 21st Century product. (Consider it the "Express" edition of Borland C++ Studio.) If you are using VCL, then the KeyDown event includes the ctrl/alt/shift state as an argument. If you are writing a console application, then have a look at the Turbo C++ help on GetKeyState() and related functions. (There is another way to do it, but I''ve forgotten...)
这篇关于使用Turbo C ++测试是否按下了键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文