473,387 Members | 1,603 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,387 software developers and data experts.

looking for a combi function of kbhit() and getch()

please help me !
1) i m trying to move a character using the arrow key, but dont know how to scan the arrow key.
2) form a while(1) loop i have to break, when a key is pressed(cant use getch() as the while loop should break only on pressing a key and should not wait for a user i/p all the time in the loop), and also know the what key was pressed. how do i achieve this?
Oct 16 '06 #1
2 8364
Banfa
9,065 Expert Mod 8TB
Understanding that this is platform specific to Windows,

Expand|Select|Wrap|Line Numbers
  1. char c;
  2.  
  3. for(;;)
  4. {
  5.     if (_kbhit() != 0)
  6.     {
  7.         c = (char)_getch();
  8.  
  9.         if (c==0 || c==0xE0)
  10.         {
  11.             c = (char)_getch();
  12.             // Handle arrow key hit c
  13.         }
  14.         else
  15.         {
  16.             // Handle normal key hit c
  17.         }
  18.     }
  19. }
  20.  
Oct 16 '06 #2
vivicio047,

You should consider that several keys (F1,...F12, arrow keys) will produce two bytes, not one. The first of these 2 bytes is 0x00, the second is key specific.
In case a call of getch function produces 0x00, a second call a second call of getch is necessary.
Nov 22 '10 #3

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

Similar topics

0
by: dbrown2 | last post by:
I'm having some trouble using kbhit inside the editor enviroments. I'm using win2000 with Python2.3 and win32all v157 versions. Any pointer on how this should be handled would be appreciated. Is...
1
by: Hans Georg Krauthaeuser | last post by:
Hey all, this is probably a FAQ, but I didn't found the answer... I use msvcrt.kbhit() to check for a user keyboard event on windows. But now, I would prefer to make the module independent...
2
by: Shugong Wang | last post by:
getch() function is not a standard C/C++ function. Thought gcc provieds ncurses.h and a getch() function is realized, I still want to know how to realize a getch() function in standard c or c++.
6
by: exquisitus | last post by:
Hi all, I'm porting a DOS application to run on Linux. I need to replace this function or use an equivalent. Anyone knows how or where I can get this function's equivalent (or maybe someones...
4
by: oketz1 | last post by:
is there any function like this? Console.Read is not good for me because I dont want to click Enter after reading an input. thanks , Okets
1
by: Carsten Orthbandt | last post by:
This code: ---snip--- #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include <stdio.h> #include <tchar.h> #include <conio.h> int _tmain(int argc, _TCHAR*...
9
by: Arun | last post by:
I recently came to know that using int86 function with interrupt number 22 we can identify keystrokes. I want to know whether this is in any way different from getch() function. any help on this...
45
by: simnav | last post by:
In the following code something strange happens ! If I keep pressed any of ALT+Arrow, keys, they are extracted two times from buffer then getch seems to stop; if I release and press again ALT+arrow...
1
by: SpecialKay | last post by:
hey guys, i have a threaded program, i have loop that contunes until i get a kbhit() then, i playback repetively untill i get another kbhit(). EDIT: the first kbhit happens on a child thread of...
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: 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,...
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.