Detecting a key combination


 
Thread Tools Search this Thread
Top Forums Programming Detecting a key combination
# 8  
Old 12-20-2006
In the following code I scan the Ctrl+L and it returned the value 12 but it needs a enter key. Is there any function in Unix (C) so that the typed char should not appear on the screen. Like one in windows available in conio.h. I din have the conio in Unix.Why?

main()
{
char i;
i=getc(stdin);

printf("%d\n",i);
if(i==12)
{ system("clear");
printf("\b");
}
}
# 9  
Old 12-20-2006
Can you read the above posts? They tell you what to do and where to look - we are not writing the code for you. hint: non-canonical
# 10  
Old 12-21-2006
Thanks to all for their kind help. I implemented it as following:
Code:
#include<termios.h>
#include<unistd.h>
main()
{
    char i;
    i=getch();
    
    printf("%d\n",i); 
    if(i==12)
    {    system("clear");
        printf("\b");
     }   
}

int getch(void) {
      int c=0;

      struct termios org_opts, new_opts;
      int res=0;
          //-----  store old settings -----------
      res=tcgetattr(STDIN_FILENO, &org_opts);

          //---- set new terminal parms --------
      memcpy(&new_opts, &org_opts, sizeof(new_opts));
      new_opts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE |
ICRNL);
      tcsetattr(STDIN_FILENO, TCSANOW, &new_opts);
      c=getchar();
          //------  restore old settings ---------
      res=tcsetattr(STDIN_FILENO, TCSANOW, &org_opts);

      return(c);
}


The only thing I have as a problem now is How to do both at the same time in my Program. As if I press Ctrl+L , Ctrl+P they perform their necessary action given to them while if the input is a command then it should appear on the screen as in the previous this is not the case. I tried to store that in a buffer but not successful.
If I use a buffer then how that will perform if it is followed by a Ctrl.

Last edited by Perderabo; 12-21-2006 at 08:26 PM.. Reason: add code tags for readability
# 11  
Old 12-21-2006
Mobile01,

Please use code tags, it makes it very hard to read when you do not use the tags and if you want people to help you you should make it as easy as you can for them.
# 12  
Old 12-22-2006
Sorry, I will use tags from now onwards.

Thanks


Please help with the problem
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Kill -9 -1 combination

Good morning, In a Production environment ive seen this command that kills processes kill -9 -1 Because i am in a production environmet i can not execute this comamnd, so i would like to know what is the difference for the conventional kill -9 PID ? Thanks a lot (11 Replies)
Discussion started by: alexcol
11 Replies

2. Shell Programming and Scripting

Combination of 6 nos

Hi folks, I have a numbers from 1-100 and from these nos I have 30 numbers.. From this 30 nos, I have to generate a combination of 6 nos... this 30 numbers will range from 1-100... ( FYI: This is not a lottery game - just kidding) ... I am trying out this in a shell script.. any ideas ? (3 Replies)
Discussion started by: gsiva
3 Replies

3. Programming

6 digits combination

Is there any program that can create 6 digit numbers with: (DIGIT_1)+(DIGIT_2)+(DIGIT_3)+(DIGIT_4)+(DIGIT_5)+(DIGIT_6)=10 Any perl or C also can. Anyone can help me? Thank you (6 Replies)
Discussion started by: Tzeronone
6 Replies

4. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

5. Shell Programming and Scripting

Detecting key combination in bash

I need to grab key combination from a bash script and store it in a variable. Is there any way to do this? Thanks in advance! (1 Reply)
Discussion started by: prism1
1 Replies

6. Solaris

Solaris 8 ssh public key authentication issue - Server refused our key

Hi, I've used the following way to set ssh public key authentication and it is working fine on Solaris 10, RedHat Linux and SuSE Linux servers without any problem. But I got error 'Server refused our key' on Solaris 8 system. Solaris 8 uses SSH2 too. Why? Please help. Thanks. ... (1 Reply)
Discussion started by: aixlover
1 Replies

7. UNIX for Dummies Questions & Answers

Starting terminal with shortcut key combination

How can the shortcut keys be defined that would open up a terminal window? When using a kvm switch, the mouse sometimes does not work, but the keyboard does, and by opening up a terminal window using a shortcut key combination, the mouse can be restarted by entering the predefined mouserestart... (0 Replies)
Discussion started by: figaro
0 Replies

8. UNIX for Dummies Questions & Answers

Pressing backspace key simulates enter key

Hi, Whenever i press the backspace key, a new line appears, i.e. it works like a enter key. :confused: Thanks (2 Replies)
Discussion started by: vibhor_agarwali
2 Replies

9. SuSE

Disabling interrupt function of Control-C key combination

I am using informix RDBMS over SUSE LINUX. In linux if you press control-c it acts as an interrupt key. In my program I have used control-c to perform certain functions but it is being overriden by interrupt function of control-c key combination of SUSE LINUX. Kindly suggest me a solution by which... (1 Reply)
Discussion started by: V.V.KUMAR
1 Replies
Login or Register to Ask a Question