Sponsored Content
Top Forums Programming How do you detect keystrokes in canonical mode? Post 302573811 by Corona688 on Tuesday 15th of November 2011 05:33:57 PM
Old 11-15-2011
Quote:
Originally Posted by Ultrix
Except I've noticed that the bash shell can detect the arrow keys (e.g. to move through history) without the user having to press enter, even though it shows ICANON turned on when I run stty. How does it do this?
It's not magic. Looking at bash 4.0's source code, specifically lib/sh/shtty.c:

Code:
int
tt_setonechar(ttp)
     TTYSTRUCT *ttp;
{
#if defined (TERMIOS_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER)

  /* XXX - might not want this -- it disables erase and kill processing. */
  ttp->c_lflag &= ~ICANON;
...

The very first thing it does when setting the terminal to read input is turn off canonical mode.

It turns canonical mode back on when running external commands, because they expect and need it. stty is an external command, so...
This User Gave Thanks to Corona688 For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

recording keystrokes in vi

What is the syntax for recording command in vi. If I want to repeat a command over and over. My file is 12/01/05,,adsmte,9,0,0 12/02/05,,adsmte,12,0,0 12/03/05,,adsmte,10,0,0 12/04/05,,adsmte,11,0,0 12/05/05,,adsmte,10,0,0 12/06/05,,adsmte,10,0,0 12/01/05,,tsmpc1,57,1,2... (5 Replies)
Discussion started by: reggiej
5 Replies

2. Shell Programming and Scripting

tool to emulate keystrokes out to a ps/2 device?

hey all, i am trying to connect my mac to my sony DVD changer so that i can control one aspect of it with any kind of shell script or program. the DVD player allows you to plug in a PS/2 keyboard to navigate it's on screen menu. what i want to do is use my mac to navigate my own menus, then... (0 Replies)
Discussion started by: drzoomn
0 Replies

3. Programming

Help with stdin and non-canonical mode

I am writing a more command for my class, and have it most of the way done, but with my current implimentation when I pipe stdin to my code it doesnt use my non-canonical/non echo settings I set for the terminal window. Do I need to specify a different terminal in order for this to work ? It works... (1 Reply)
Discussion started by: petricore
1 Replies

4. UNIX for Dummies Questions & Answers

Looking for an X11 Utility - Send Keystrokes to Multiple Clients

A long time ago, I frequently used a small X11 utility that allows you to manage multiple systems at the same time. It worked by opening a small window that had a button you used to "Add" X Clients to it. These would be xterms on different systems for example. You would then type inside that... (5 Replies)
Discussion started by: Alon.Albert
5 Replies

5. Shell Programming and Scripting

Queueing keystrokes

Hello, I have a ksh which can be run interactively with read etc waiting for input and so forth. Do you have an idea how can I invoke the ksh and supply a sequence of keystrokes that will feed the executable flow so that it will automatically run as if someone actually walked through one prompt... (7 Replies)
Discussion started by: gio001
7 Replies

6. OS X (Apple)

Any mac software for recording keystrokes

I'm trying to find a good keylogger that doesn't come with any viruses. It happens to me several times that my browser crashes when I am in article writing or some other thing, very annoying. Thus, I need a keylogger to keep all my keystroke recorded. I 'v tried some, like the Aobo Mac Keylogger,... (1 Reply)
Discussion started by: Bluerosen
1 Replies

7. UNIX for Advanced & Expert Users

Sending keystrokes to another process

The third-party ERP system used by our company has no idle-out facility and we sometimes have issues because users simply walk away from their computers and leave sessions logged in for hours or even go home without logging out. (We are in a factory environment so it is hard to raise the care... (7 Replies)
Discussion started by: Wayne Ivory
7 Replies

8. Solaris

DNS service is in maintenance mode. How to bring it back to online mode?

:confused: when i tried to look the status of DNS-client, it is in maintenance mode..... Please tell me how to bring it back to online mode...PLEASE TELL ME STEP BY STEP.... PLEASE... :wall: (2 Replies)
Discussion started by: vamshigvk475
2 Replies

9. Shell Programming and Scripting

Record and re-use keystrokes

We have a FORTRAN program that creates a report for our client. The client makes a number of selections as to what will appear on the report. However, the client has to repeat this everytime the report is run. I am trying to find a way to record what they've selected (their keystrokes) in UNIX and... (22 Replies)
Discussion started by: KathyB148
22 Replies
sttyv6(7)						 Miscellaneous Information Manual						 sttyv6(7)

NAME
sttyv6: stty - terminal interface for Version 6/PWB compatibility DESCRIPTION
These routines attempt to map the UNIX Time-Sharing System, Sixth Edition (Version 6), and PWB stty and gtty calls into the current ioctls that perform the same functions. The mapping cannot be perfect. The way the features are translated is described below. The reader should be familiar with before studying this entry. The following data structure is defined in the include file struct sgttyb { char sg_ispeed; /* input speed */ char sg_ospeed; /* output speed */ char sg_erase; /* erase character */ char sg_kill; /* kill character */ int sg_flags; /* mode flags */ } The flags, as defined in sgtty.h, are: define HUPCL define XTABS define LCASE define ECHO define CRMOD define RAW define ODDP define EVENP define ANYP define NLDELAY define TBDELAY define CRDELAY define VTDELAY define BSDELAY define CR0 define CR1 define CR2 define CR3 define NL0 define NL1 define NL2 define NL3 define TAB0 define TAB1 define NOAL define FF0 define FF1 define BS0 define BS1 When the command (ioctl is executed, the flags in the old structure are mapped into their new equivalents in the structure. Then the com- mand is executed. The following table shows the mapping between the old flags and the current flags. Note that flags contained in the structure that are not mentioned below are cleared. HUPCL (if set) sets the termio HUPCL flag; HUPCL (if clear) clears the termio HUPCL flag; XTABS (if set) sets the termio TAB3 flag; XTABS (if clear) clears the termio TAB3 flag; TBDELAY (if set) sets the termio TAB1 flag; TBDELAY (if clear) clears the termio TAB1 flag; LCASE (if set) sets the termio IUCLC, OLCUC, and XCASE flags; LCASE (if clear) clears the termio IUCLC, OLCUC, and XCASE flags; ECHO (if set) sets the termio ECHO flag; ECHO (if clear) clears the termio ECHO flag; NOAL (if set) sets the termio ECHOK flag; NOAL (if clear) clears the termio ECHOK flag; CRMOD (if set) sets the termio ICRNL and ONLCR flags; also, if CR1 is set, the termio CR1 flag is set, and if CR2 is set, the termio ONOCR and CR2 flags are set; CRMOD (if clear) sets the termio ONLRET flag; also, if NL1 is set, the termio CR1 flag is set, and if NL2 is set, the termio CR2 flag is set; RAW (if set) sets the termio CS8 flag, and clears the termio ICRNL and IUCLC flags; also, default values of 6 characters and 0.1 seconds are assigned to MIN and TIME, respectively; RAW (if clear) sets the termio BRKINT, IGNPAR, ISTRIP, IXON, IXANY, OPOST, CS7, PARENB, ICANON, and ISIG flags; also, the default values control-D and null are assigned to the control characters EOF and EOL, respectively; ODDP (if set) if EVENP is also set, clears the termio INPCK flag; otherwise, sets the termio PARODD flag; VTDELAY (if set) sets the termio FFDLY flag; VTDELAY (if clear) clears the termio FFDLY flag; BSDELAY (if set) sets the termio BSDLY flag; BSDELAY (if clear) clears the termio BSDLY flag. In addition, the CREAD bit is set, and, if the baud rate is 110, the CSTOPB bit is set. When using the ispeed entry in the structure is mapped into the appropriate speed in the CBAUD field. The erase and kill entries are mapped into the erase and kill characters. When the (ioctl command is executed, the command is first executed. The resulting structure is then mapped into the structure, which is then returned to the user. The following table shows how the flags are mapped into the old structure. Note that all flags contained in the structure that are not mentioned below are cleared. HUPCL (if set) sets the sgttyb HUPCL flag; HUPCL (if clear) clears the sgttyb HUPCL flag; ICANON (if set) sets the sgttyb RAW flag; ICANON (if clear) clears the sgttyb RAW flag; XCASE (if set) sets the sgttyb LCASE flag; XCASE (if clear) clears the sgttyb LCASE flag; ECHO (if set) sets the sgttyb ECHO flag; ECHO (if clear) clears the sgttyb ECHO flag; ECHOK (if set) sets the sgttyb NOAL flag; ECHOK (if clear) clears the sgttyb NOAL flag; PARODD (if set) sets the sgttyb ODDP flag; PARODD (if clear) clears the sgttyb ODDP flag; INPCK (if set) sets the sgttyb EVENP flag; PARODD, INPCK (if both clear) sets the sgttyb ODDP and EVENP flags; ONLCR (if set) sets the sgttyb CRMOD flag; also, if CR1 is set, the sgttyb CR1 flag is set, and if CR2 is set, the sgttyb CR2 flag is set; ONLCR (if clear) if CR1 is set, the sgttyb NL1 flag is set, and if CR2 is set, the sgttyb NL2 flag is set; TAB3 (if set) sets the sgttyb XTABS flag; TAB3 (if clear) clears the sgttyb XTABS flag; TAB1 (if set) sets the sgttyb TBDELAY flag; TAB1 (if clear) clears the sgttyb TBDELAY flag; FFDLY (if set) sets the sgttyb VTDELAY flag; FFDLY (if clear) clears the sgttyb VTDELAY flag; BSDLY (if set) sets the sgttyb BSDELAY flag; BSDLY (if clear) clears the sgttyb BSDELAY flag. When using the CBAUD field is mapped into the ispeed and ospeed entries of the structure. Also, the erase and kill characters are mapped into the erase and kill entries. Note that, since there is not a one-to-one mapping between the and structures, unexpected results may occur when using the older and calls. Thus, the and calls should be replaced in all future code by the current equivalents, and respectively. WARNINGS
These facilities are included to aid in conversion of old programs, and should not be used in new code. Use the interface described in Note that these conversions do work for programs ported from UNIX Time-Sharing System, Seventh Edition (Version 7), because some V7 flags are defined differently. SEE ALSO
stty(2), termio(7). sttyv6(7)
All times are GMT -4. The time now is 12:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy