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.

Checking if a key is pressed using the gcc compiler in windows

So my teacher is having us use the cygwin gcc compiler to program things in c, but the gcc compiler doesn't have conio.h included in it nor does it seem to have curses.h. I am just wondering if there is a simple method to either create my own kbhit function or just include a specific header file other than the two I mentioned earlier. Thanks
Nov 19 '14 #1

✓ answered by kulaanthenord

So I figured out a way to do it.

Basically, making my own getch() function in which it calls a few system commands.

Expand|Select|Wrap|Line Numbers
  1. char getch();
  2.  
  3. char getch()
  4. {
  5.     //Gets the raw input
  6.     system( "stty raw" );
  7.     //Sets the buffer to not echo onto the screen
  8.     system( "stty -echo" );
  9.     //gets the input
  10.     char input = getchar();
  11.     //resets the input
  12.     system( "stty cooked" );
  13.     //sets the buffer to echo
  14.     system( "stty echo" );
  15.     return input;
  16. }
This is definitely not the way I would wish to perform this task, however, it works.

3 2062
divideby0
131 128KB
There is no standard way of replicating kbhit, getch, etc as the standard input functions are buffered and block while waiting on user input.

I remember reading an article somewhere where buffering could be turned off, but it's not portable. Try milling over the results from google and see if any will work for your situation.

Good luck
Nov 19 '14 #2
Alright. I've been googling for about an hour so far with no luck as of yet. Thanks for the information though.
Nov 19 '14 #3
So I figured out a way to do it.

Basically, making my own getch() function in which it calls a few system commands.

Expand|Select|Wrap|Line Numbers
  1. char getch();
  2.  
  3. char getch()
  4. {
  5.     //Gets the raw input
  6.     system( "stty raw" );
  7.     //Sets the buffer to not echo onto the screen
  8.     system( "stty -echo" );
  9.     //gets the input
  10.     char input = getchar();
  11.     //resets the input
  12.     system( "stty cooked" );
  13.     //sets the buffer to echo
  14.     system( "stty echo" );
  15.     return input;
  16. }
This is definitely not the way I would wish to perform this task, however, it works.
Nov 20 '14 #4

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

Similar topics

1
by: Oleg | last post by:
Hi People, Does anybody knows how to set up a V.S. .NET. I am trying to use Windows libraries in my code, but got en error that library in not found, not installed, etc. here is the simple...
5
by: Dave | last post by:
How do I check in a Windows Forms app if any controls have changed? I have a form that collects data, and I want to prompt the user if they try to exit the app, or load a new file, without saving...
5
by: Richard Lionheart | last post by:
Hi All, I tried creating a C# Form using Petzold's "Programming MS Windows with C#" guidance. He recommended using the namespace System.Windows.Forms. However, VS.NET claims "the type or...
2
by: Mario | last post by:
Hi, I am trying to create an application with multiple windows forms. The problem that I have is that after creating the window forms, I do not know how to open formN after closing Main form. ...
2
by: pratcp | last post by:
I have a remote server (a shared hosting webserver) where I have few users ftp some flat files. I need to access these files using a windows app/windows service written using c# and run it on a...
9
by: garyusenet | last post by:
I am using a C# solution that somebody kindly sent me. It was a console application. I am trying to get use of the MessageBox. I have added the following using directive to the namespaces at...
3
by: piedpiper | last post by:
Dear All, When i use: using System.Windows.Forms; I get the following error when compiling: Error 3 : The type or namespace name 'Windows' does not exist in the namespace 'System' (are you...
11
by: rb0135 | last post by:
Hi all (and Mark). As I have posted a few times the last few weeks about my GPS application, I have got to the point of adding the GPS stuff in. I am using the Windows Mobile 6 SDk and used the...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.