Solved

Evaluating keyboard entries

Posted on 2000-03-11
4
220 Views
Last Modified: 2010-04-15
I managed to turn off the input buffer on the terminal so i can process one key character at a time.  My question is how can i evaluate the keys (especially the arrow and function) when the user presses them and do a certain action on whatever key is pressed.

We have an AIX Unix.

Thanks
0
Comment
Question by:alvinrc
  • 2
  • 2
4 Comments
 

Expert Comment

by:nadt
ID: 2609009
I think this should work

int readkey(int *function_key)
{
  char tempkey;

  *function_key=0;
  tempkey=getch();
  if (tempkey==0)
  {
     function_key=1;  
     tempkey=getch();
  }
  return(tempkey);
}

you can cut paste this procedure in your program as-is.  What this procedure essentially does is:-

1)  if special key is pressed it returns its ascii number and sets *function_key=1;  prompting you that a special key like arrow or esc has been pressed.  
2)  if normal key is pressed it returns its ascii number and sets *function_key=0;  prompting you that is a normal key has been pressed.  

call this function in your program as:-

int isfunct;
int xyz;
xyz=readkey(&isfunc);


hope this helps,
nadt
0
 

Author Comment

by:alvinrc
ID: 2613523
Adjusted points to 85
0
 

Author Comment

by:alvinrc
ID: 2613524
Im using a Unix C, i think the getch() function is for ms dos c, and when i try this

char tempkey
tempkey = getchar()

the tempkey wont come out as zero eventhough
i type in esc or any special chars
0
 

Accepted Solution

by:
nadt earned 85 total points
ID: 2614860
alvinrc,
Sorry I am not very conversent with unix but I think if i give u an assembly language code containing bios interrupts it should work.  'cause Whatever u're os is whatever language u use it can understand assembly bios interrupts.  Paste this code in any of u're functions like this:-

_asm
{
mov ah,00h;
int 16h;

/*what these two lines will do is that they will invoke bios-interrupt 16h with function 00h which is `get a character from keyboard'

after executing these two lines u will have `ah' containing the scan code (0 or 1) depending on whether spacial character has been pressed or not and `al' will contain the ascii of your interest.  You can write following instruction to validate the same
/*
mov boolean,ah;
mov character,al;

do_validation;
}

This will surely help.
regards
nadt
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

Suggested Solutions

Title # Comments Views Activity
how to define a string array with big size in c language 10 143
Adjust Mfcapp 29 172
Want to delete all my personal data 13 146
What is atomic operation? 6 64
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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops 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