![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2004
Posts: 2
Rep Power: 0
![]() |
Simple Program, kbhit() and beep
I'm supposed to make a program that beeps everytime any key is pressed. I thought this would be easy with an if or maybe even a do while and kbhit() but I can't get any output from this program and I can only get this code to compile in borland C++ builder 6 I tried it in dev ++ and it didn't recognize the beep command. Any insight would be appreciated thanks in advance.
#include "windows.h" #include <stdio.h> #include <iostream.h> #include <conio.h> int main(){ if(kbhit()) { Beep( 800, 600 ); } } |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
conio.h is a non-standard header. It is a borland specific thing and should be avoided at all costs. I would suppose kbhit and/or Beep is defined there. So Dev-C++ is not happy.
With that said, the reason it's not working is because if(kbhit()) only checks for a keyboard hit when the application starts running. It doesn't get one so the application dies. You could do something like: bool keyboardHit = false;
while(!keyboardHit) {
if(kbhit()) {
Beep(800, 600);
keyboardHit = true;
}
}As I mentioned, conio is a non-standard header. Look for a blocking way to read a key from the keyboard and then write a '\a' character to the console (alarm beep). |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Apr 2005
Posts: 12
Rep Power: 0
![]() |
You might not have the right libary for Dev C++ I only use one kind of compiler and libary. So I am not sure if this is possible.
![]()
__________________
:D :eek: :cool: Joe Thompson |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
i didn't think conio.h was a borland specific header?!? Doesn't matter much to me though, either way because I rarely use it.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Nov 2004
Posts: 2
Rep Power: 0
![]() |
Thanks for the response, and I'm working at learning more but the book I have is horrible. I need it for a class at school though because all the tests are based off of it. Its really outdated and for Borland Turbo C++, many of the instructions are including borland libraries. Anyways thanks again see you around.
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Feb 2005
Posts: 22
Rep Power: 0
![]() |
no i dont think conio.h is borland specific. I have used it in Turbo C as well. But in gcc it does not work
anyway why not try "\a" ..even that gives a beep sound |
|
|
|
|
|
#7 | |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Quote:
Actually the digital mars compiler includes it too but last time I checked that compiler is far too outdated to be considered useable. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|