Solved

how to read function keys in c/c++

Posted on 2004-04-14
9
937 Views
Last Modified: 2012-08-13
hi all,
 how to read function keys like arrow keys,ctrl,alt,f1,f2...etc in c/c++.
i tried with getch(),but it is working with other characters(may be not sure but i thinks it works for printable characters).plz help me...

bye
ramu
0
Comment
Question by:ramuguda
9 Comments
 
LVL 12

Expert Comment

by:stefan73
ID: 10821805
Hi ramuguda,
I you are on Windows, the probably easisest way should be DirectInput.

Cheers,
Stefan
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10821841
You can use bioskey() if you are using Borland's compilers,either Borland C++ or TurboC++
You need bios.h for this.
If you have this header,post back if you need more details,
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10821860
#include<conio.h>
#include <stdio.h>
#include <bios.h>
int main(void)
{
   int key;
   clrscr();
   while (!bioskey(1));
   /* function 1 returns 0 until a key is pressed */
   /* function 0 returns the key that is waiting */
   while(key!=283)//loop till escape pressed
   {
   key = bioskey(0);
   printf("%d\n",key);
   }
   return 0;
}
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 8

Expert Comment

by:ssnkumar
ID: 10822220
If you are on Linux, you will have to use ncurses library to achieve this.

-ssnkumar
0
 

Author Comment

by:ramuguda
ID: 10829388
hi ankuratvb,
 i don't have bios.h header file...i am using dev c++ compiler and vc++ compiler...i am workin on windows operating system...how can we read function keys without using header file(bios.h)...

 can you tell me where can i download turbo or borland compilers...

bye
ramuguda
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10829569
I wouldnt really recommend you downloading these older compilers.
I am sure there are ways to do this in VC as well.Just wait,

If nothing happens,then try out these compilers:

Turbo C version 2.01 can be downloaded from http://community.borland.com/article/0,1410,20841,00.html 

I guess version 3 is also available.Visit their site.
0
 

Author Comment

by:ramuguda
ID: 10830228
hi ankuratvb,

 iam getting it in turbo c compiler...but if i copy the bios.h into include folder of vc++ compiler..iam getting linking error like...
unresolved external symbol "int __cdecl bioskey(int)" ...

 can you tell me how can we read these function keys without using this header file...i want atleast reading arrowkeys...

bye
ramuguda
0
 
LVL 9

Accepted Solution

by:
ankuratvb earned 50 total points
ID: 10832552
Hi,
Just copying the header wont do.You need the library as well which is dif. for dif. environments and compilers.

If you only want arrow keys,getch() will work:
72,75,77,80 are the codes for up,left,right and down arrow keys.
0
 

Author Comment

by:ramuguda
ID: 10836653
hi ankuratvb,
 thanks...can you tell how can we read other function keys with out using header files...

bye
ramuguda
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question