?
Solved

C and special keys

Posted on 2003-03-10
7
Medium Priority
?
174 Views
Last Modified: 2010-04-15
I wonder if anyone could let me know or give me a  code sample on how to read the special keys in C (ie Escape Key, Ctrl, Alt do if user preses those key I can do the action) and also how do you desable the ctrl+c or ctrl+q in C

thanks a bunch 150 for this

Ledeni
0
Comment
Question by:ledeni
[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
  • 5
  • 2
7 Comments
 
LVL 8

Expert Comment

by:akshayxx
ID: 8107081
what OS and what compiler u working with ..
btw on linux and all Unix the way to isable ctrl+c is


#include <signal.h>

and somewhere in ur program preferrably at the start of main or initialisation function make this call

signal(SIG_IGN,SIGINT);

this will enable your prgram to ignore the signal SIGINT , which is sent to your program when u press ctrl+c, while ur program running in the foreground
0
 

Author Comment

by:ledeni
ID: 8107355
hey it is a UNIX and gcc compiler ... I will give it a shot in this signal thing ... would you know how to prompt the user withous them presing the "enter" after the enter the value ???

Thanks for your hep and time
0
 
LVL 8

Expert Comment

by:akshayxx
ID: 8107422
>>would you know how to prompt the user withous them presing the "enter" after the enter the value ???

i didnt get this .. can u explain .. then i can be of better help
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 8

Expert Comment

by:akshayxx
ID: 8107484
what is the value that u want to read ,

btw u must have a look at the ncurses library on linux..
it provides all the no-enter-character-read functions , and other console based screen manipulation ..
like printing a menu and reading a value from 5th line 10th column in the console window
0
 
LVL 8

Accepted Solution

by:
akshayxx earned 600 total points
ID: 8107671
here is very very trivial ncurses program that reads the keys, and prints them out without u pressing enter .. look what it does when u press enter

compile it with
gcc filename.c -lncurses
OR
gcc filename.c -lcurses

#include <stdio.h>
#include <curses.h>
main(){
char c;
initscr(); noecho();

             intrflush(stdscr, FALSE);
             keypad(stdscr, TRUE);

while((c=getch())!=EOF){
printf("u pressed <%s>",keyname(c));fflush(stdout);
wrefresh(stdscr);
}


}
0
 

Author Comment

by:ledeni
ID: 8107921
works for me :) THanks a bunch !!!
0
 
LVL 8

Expert Comment

by:akshayxx
ID: 8107937
welcome
0

Featured Post

Industry Leaders: 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

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…
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…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files 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.
Suggested Courses

777 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