The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
combination of two commands nehaquick UNIX for Dummies Questions & Answers 3 02-01-2008 04:09 AM
awk and file combination sickboy UNIX for Dummies Questions & Answers 1 06-13-2005 09:02 PM
Combination Of commands rahulrathod UNIX for Dummies Questions & Answers 2 12-14-2004 07:32 AM
Combination of gunzip and tar on Solaris dwidmer SUN Solaris 5 11-21-2003 12:17 AM
Partition combination gardarm Filesystems, Disks and Memory 3 03-14-2002 07:35 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-30-2006
mobile01 mobile01 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 24
Detecting a key combination

Could anybody tell me how I can detect a particular key combination and perform a particular task on that event. e.g. if I press Ctrl + L on the shell then it clears the screen. Please tell me how it can be performed on my shell.
And how the Arrow Keys can be detected. I tried but pressing a key once is returning 3 values namely 26,27,(A,B,C,D) The last one differs only.

Please tell me how to call a function or to execute a line of code when a particular event occurs.




Thanks
  #2 (permalink)  
Old 11-30-2006
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,928
Have a look at the curses library and it's getkey() function.
  #3 (permalink)  
Old 11-30-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
There are only so many of these that you can define, those things are defined for you in the man page for stty.

AS an example, suppose you want the backspace key to delete the previous character, then put a line like this in your .profile or .bashrc file in your home directory. The next time you login, it takes effect - or you can source the file to make it work right away

Code:
stty erase "^H"
The erase command tells stty to have your terminal erase a character - "^H" written just the way I have it. You need to define the keys the way you want them.

stty functions are part of the termios set of functions - try termios if you want to do this in C.
  #4 (permalink)  
Old 11-30-2006
mobile01 mobile01 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 24
Some more help

Could you please clarify my problem
I am making a program in C
Now I am getting the string from the user then How I can put it in that state that what user has hitted.
Any sample will me a great help




Thanks
  #5 (permalink)  
Old 12-17-2006
mobile01 mobile01 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 24
Please Help

How I can detect a particular Key Combination through programming in Unix.

to trap the signals there are methods but control+L is not detected as a signal so how can I detect that combination of Key Hit and how to detect the Arrow Key Hits as each key hit is itself returning three values
The first two values of all four keys is same only the last key value is different.

I tried to use the getkey function of curses and select and poll funtions but my problem is not solved please help...



Thanks
  #6 (permalink)  
Old 12-17-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Let's try this again
1. all keystrokes go thru the tty driver. Period. If your driver interprets them they are interpreted BEFORE you program ever sees them. termios() can remove/add settings.

2. For 2 key ctrl sequences [A-Z] the terminal returns ASCII 1-26 (minus those interpreted by the driver as something else) ctrl-L is 12, ASCII form feed. There are other two-key sequences as well.

3. If you want to be able to create special responses to other key sequences like the function keys or alt key combinations you use the curses or ncurses library.

In general, if you want to play with single key combinations like a GUI does, you have to set the terminal to non-canonical mode. I've posted the code to do that on the forums several times - you can search for it.
  #7 (permalink)  
Old 12-17-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Quote:
Originally Posted by jim mcnamara
In general, if you want to play with single key combinations like a GUI does, you have to set the terminal to non-canonical mode. I've posted the code to do that on the forums several times - you can search for it.
Also, I have posted the code to do that, but only one time. But I also wrote a FAQ article, scripts/programs/code posted to www.unix.com, which has a link to it. So if mobile01 had either looked at the faqs or used the search function, he would already have the answer.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0