Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

C and special keys

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
ledeni
Asked:
ledeni
  • 5
  • 2
1 Solution
 
akshayxxCommented:
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
 
ledeniAuthor Commented:
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
 
akshayxxCommented:
>>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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
akshayxxCommented:
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
 
akshayxxCommented:
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
 
ledeniAuthor Commented:
works for me :) THanks a bunch !!!
0
 
akshayxxCommented:
welcome
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!

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now