Solved

Evaluating keyboard entries

Posted on 2000-03-11
4
194 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
Comment Utility
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
Comment Utility
Adjusted points to 85
0
 

Author Comment

by:alvinrc
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now