Solved

Evaluating keyboard entries

Posted on 2000-03-11
4
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
libcurl - taking long time on curl_easy_perform 11 503
C hashtable library 3 114
MySQL recovery 7 60
calling back function with same name and different signature 1 42
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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.

739 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