473,466 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

3 New Member
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 2065
divideby0
131 New Member
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
kulaanthenord
3 New Member
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
kulaanthenord
3 New Member
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: 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
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.