Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to know how to test whether the key shift, ctrl and alt are pressed or not using Turbo C++ code.
Posted
Updated 2-Sep-10 1:47am
v2

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
 
Share this answer
 
Comments
Peter_in_2780 2-Sep-10 21:15pm    
see my answer below...P
You may try the kbhit() function (though I'm not sure it will make the trick). Why dont' you use a more updated development tool, like, for instance Visual C++ Express Edition (it's free)?
:)
 
Share this answer
 
Comments
Peter_in_2780 2-Sep-10 21:15pm    
see my answer below ...P
ThatsAlok 3-Sep-10 3:00am    
if i would, i never want to stop programming in turbo c++.. but no company actually want to program for dos now. thats why shifted my guards and programming in visual studio!
CPallini 3-Sep-10 3:21am    
If I would I never want to stop programming in Z80 Assembly for my Spectrum...
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...)
 
Share this answer
 
Comments
ThatsAlok 3-Sep-10 2:58am    
i doubt that..turbo c++ is quite old application, which used to run dos plateform. I am sure dos is not 21st century product, it's consider outdated in 20th century itself
CPallini 3-Sep-10 3:05am    
We remember well, actually. Turbo C++ was born in the '90. It's evanescent revival, however, became extinct in 2006. :-)
@Alok: see 'the 21 century' product in http://en.wikipedia.org/wiki/Turbo_C%2B%2B. :-)
Peter_in_2780 3-Sep-10 3:07am    
@ThatsAlok WRONG WRONG WRONG. I run Turbo C++ 2006, and it definitely doesn't do DOS! Broland's fault for recycling the name for a totally different product.
CPallini 3-Sep-10 3:20am    
Indeed, it is a Borland fault. It's a shame you didn't use 'the original' it was really an amazing product.
Peter_in_2780 3-Sep-10 3:26am    
I did, and its even-more-amazing-for-its-time predecessor, Turbo Pascal. Absolutely blew our socks off!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900