473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

program to read key press values

can u guide me how to write this program


my program should give outputas follows

when i press a key on the keyboard it should return the "key is pressed"

and also if the key is pressed more than 350ms it should return the "key is hold"
Feb 6 '07 #1
10 54589
kbhit() is a function returns integer value whenever the key is pressed...
you can use the above function.....

Try to post the code you had written...
Feb 6 '07 #2
ok

i tried the same
but how to do the 350 ms time gap on hold key event
Feb 6 '07 #3
Please explain the code you want in clear....
Feb 6 '07 #4
#include<stdio.h>
#include<conio.h>
void main()
{
printf("enter key a");
while(kbhit()='a')
{
printf("key a is pressed");
}
}
but it is saying that lvalue required i entered ascii value also .
how to get "something done" when a mentioned key is pressed
Feb 6 '07 #5
check the while loop condition are you comparing or assiginig...
Check it.......
Feb 6 '07 #6
willakawill
1,646 1GB
kbhit() returns 0 if the keyboard has not been hit and a nonzero value if it has been hit. It does not return the value of the key that has been hit e.g.
Expand|Select|Wrap|Line Numbers
  1. /* KBHIT.C: This program loops until the user
  2.  * presses a key. If _kbhit returns nonzero, a
  3.  * keystroke is waiting in the buffer. The program
  4.  * can call _getch or _getche to get the keystroke.
  5.  */
  6.  
  7. #include <conio.h>
  8. #include <stdio.h>
  9.  
  10. void main( void )
  11. {
  12.    /* Display message until key is pressed. */
  13.    while( !_kbhit() )
  14.       _cputs( "Hit me!! " );
  15.  
  16.    /* Use _getch to throw key away. */
  17.    printf( "\nKey struck was '%c'\n", _getch() );
  18.    _getch();
  19. }
which is the example shown in vs6 help
Feb 6 '07 #7
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <time.h>

int main()
{
int m;
clock_t st,end,end_out;
clrscr();
st=clock();
printf("The value of the clock is : %f\n",st/CLK_TCK);
do
{

if(kbhit())
{
if((m=getch())==97)
{
end=clock();
printf("Key a is pressed....\n");
printf("The value of the clock in sec : %f\n",end/CLK_TCK);
}
}
}while(1);
getch();
return 0;
}



I think the above code will help you understand more...Clock is used measure the time taken to complete the execution
Feb 6 '07 #8
thanks for u r advice i got much from u r program
Feb 7 '07 #9
dusty
12
[quote=rajesh6695]#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <time.h>

int main()
{
int m;
clock_t st,end,end_out;
clrscr();
st=clock();
printf("The value of the clock is : %f\n",st/CLK_TCK);
do
{

if(kbhit())
{
if((m=getch())==97)
{
end=clock();
printf("Key a is pressed....\n");
printf("The value of the clock in sec : %f\n",end/CLK_TCK);
}
}
}while(1);
getch();
return 0;
}


Hi all,

I was looking for a similar program, but when I compiled this program in linux, i got an error message which goes:

stopwatch.cpp:2:19: conio.h: No such file or directory
stopwatch.cpp: In function `int main()':
stopwatch.cpp:10: error: `clrscr' undeclared (first use this function)
stopwatch.cpp:10: error: (Each undeclared identifier is reported only once for
each function it appears in.)
stopwatch.cpp:12: error: `CLK_TCK' undeclared (first use this function)
stopwatch.cpp:16: error: `kbhit' undeclared (first use this function)
stopwatch.cpp:18: error: `getch' undeclared (first use this function)

Does conio.h is only for windows. I compiled this program in cygwin. Any help please. Thanks
Feb 26 '07 #10
[quote=dusty;2395686]
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <time.h>

int main()
{
int m;
clock_t st,end,end_out;
clrscr();
st=clock();
printf("The value of the clock is : %f\n",st/CLK_TCK);
do
{

if(kbhit())
{
if((m=getch())==97)
{
end=clock();
printf("Key a is pressed....\n");
printf("The value of the clock in sec : %f\n",end/CLK_TCK);
}
}
}while(1);
getch();
return 0;
}


Hi all,

I was looking for a similar program, but when I compiled this program in linux, i got an error message which goes:

stopwatch.cpp:2:19: conio.h: No such file or directory
stopwatch.cpp: In function `int main()':
stopwatch.cpp:10: error: `clrscr' undeclared (first use this function)
stopwatch.cpp:10: error: (Each undeclared identifier is reported only once for
each function it appears in.)
stopwatch.cpp:12: error: `CLK_TCK' undeclared (first use this function)
stopwatch.cpp:16: error: `kbhit' undeclared (first use this function)
stopwatch.cpp:18: error: `getch' undeclared (first use this function)

Does conio.h is only for windows. I compiled this program in cygwin. Any help please. Thanks
I Know it's not a permanent solution but,
it's also not a very very bad idea to use online compiler
Try This Online Compiler
Jul 31 '14 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: asdasd | last post by:
Hello there, I'm hoping someone might be able to help me out. Its been awhile since I've programmed in visual basic (and roughly at that)... I want to create a program that will allow me to...
12
by: Clifford Stern | last post by:
In a function that returns two values, how do you read them? Consider the following function: int addsub(int x,int y) {int a,b; a=x+y; b=x-y; return(a,b);} trying to read the results, for...
1
by: Ranjan as usual | last post by:
Dear folks, I have a column of data in MS SQL that is being read by my VB .net program. There are a couple of blank/NULL data in those columns. How do I read that data as NULL in VB .net and then...
0
by: Chris Cairns | last post by:
Ok I have been able to use WindowsMessaging to look at all open windows applications and read some fields. It appears to work quite well with Notepad and Calculator as I can get the values as well...
4
by: kotoro | last post by:
I'm in an intro to computer programming course and just for the purposes of my test drivers and personal implementation, I would like to know if it is possible to force the program to wait for the...
0
by: Yasin cepeci | last post by:
is it possible that read string values in a filled dataset?
0
by: shantanu | last post by:
hi I am trying to read the values from a excel row. There are 89 columns for each row and same number of data in each rows. Kindly help regards shantanu
0
by: Kavitha Sudhershan | last post by:
hi, i wanna read the node values from xml. As per my code i can read the node values in first child node and for the next node am not able to read the node values. pls help me. i'll paste the code...
0
by: Manoj Deshwal | last post by:
I have a table named client_master in sqlserver and i have a windows application in c#.In c# application, there are three forms. One is to enter Client details. Second is to update the existing...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.