Ctrl key not detected in Terminal - terminal

I have a preblem with my Mac Terminal.
It is no longer able to detect the ctrl key, so I can't use anymore shortcuts like ^C to stop a running task, because when I press ctrl+C the terminal echoes only the "c" character.
I tried with stty -a and the intr seems to be ok:
speed 9600 baud; 22 rows; 80 columns;
lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl
-echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
-extproc
iflags: -istrip icrnl -inlcr -igncr -ixon -ixoff ixany imaxbel iutf8
-ignbrk brkint -inpck -ignpar -parmrk
oflags: opost onlcr -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
-dtrflow -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
eol2 = <undef>; erase = ^?; intr = ^C; kill = ^U; lnext = ^V;
min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T;
stop = ^S; susp = ^Z; time = 0; werase = ^W;
Any idea on how to solve it?

Related

How to make shortcut beginning of line ( ctrl-a ) work in kali linux?

Distribution: SMP Debian 4.9.6-3kali2 (2017-01-30)
Shell: bash
Program: Terminal emulator
Problem:
Ctrl + a Go to the beginning of the line (Home) is doing a select all
instead .
Ctrl + e Go to the End of the line (End) is working fine.
What I have tried:
stty - change and print terminal line settings
exemple: stty intr "your_new_shortcut"
$ stty -a
speed 38400 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ;
eol2 = ; swtch = ; start = ^Q; stop = ^S; susp = ^Z; rprnt =^R;
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke -flusho -extproc
Solution
The only solution that I found, at this moment is to use the Xfce terminal include in my distro.
The ctrl-a beginning of the line works fine.
The only solution that I found, at this moment is to use the Xfce terminal include in my distro.
The ctrl-a beginning of the line works fine.
I know what you mean, the terminal has the ability to move to the first character and end of line, so why wouldn't the rest of the distro be able to?
I have found a half solution with the text editor named Atom, this is just for source code management. Perhaps if you're using a more advanced source code editor like RubyMine or any of the Jetbrains suites, they'll have a different way to configure them.
For Atom:
Press the hotkey Ctrl-Comma
Navigate to Keybindings
Find the built in link called your keymap file at the beginning of the file.
Copy and paste this into there:'atom-text-editor':
'atom-text-editor':
'ctrl-e': 'editor:move-to-end-of-screen-line'
'atom-workspace atom-text-editor':
'ctrl-a': 'editor:move-to-first-character-of-line'
'ctrl-shift-a': 'core:select-all'
these controls will be more similar to MacOS. Which I assume anyone asking this question will be making the switch over from there...

change the baud rate stty on MAC terminal

I need to use USB serial cable with baud rate of 115200.
I tried to set the rate with stty command from MACbook terminal application as follows;
$stty -f /dev/tty.usbserial-A103BTIB 115200
and confirmed the settings as follows;
$stty -f /dev/tty.usbserial-A103BTIB -a
&speed 9600 baud; 0 rows; 0 columns;
lflags: -icanon -isig -iexten -echo -echoe -echok -echoke -echonl
-echoctl -echoprt -altwerase -noflsh -tostop -flusho -pendin
-nokerninfo -extproc
iflags: -istrip -icrnl -inlcr -igncr -ixon -ixoff -ixany -imaxbel -iutf8
-ignbrk -brkint -inpck -ignpar -parmrk
oflags: -opost -onlcr -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb crtscts -dsrflow
-dtrflow -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
eol2 = <undef>; erase = ^?; intr = ^C; kill = ^U; lnext = ^V;
min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T;
stop = ^S; susp = ^Z; time = 0; werase = ^W;
It looks baud rate is till 9600. Could somebody show me how to change this step by step ?
It seems like this is a common problem of stty command in OSX and not solved.
https://discussions.apple.com/thread/3798003?tstart=0
I was able to set the baudrate temporarily by running screen session
$ screen /dev/cu.usbserial-FTHHQD0C 115200
and opening another terminal to run my script.
Other option to set a rigid baud value is to:
Launch a connection with the usbserial port, redirecting the output by cat in separate terminal window (to keep the port open):
cat -v /dev/tty.usbserial-A103BTIB
Set the baud:
stty -f /dev/tty.usbserial-A103BTIB 115200
The baud value stays set.

Seperate keybindings for return, arrow-up, etc.?

I don't understand why return doesn't have it's own key when working with the readline of bash.
Using control+m is the same as using return.
How to create two separate keybindings, one for control+m and another function for return?
The same applies to arrow-up/-down etc. . Printing them quoted shows that they are not a seperate key, but a key sequence, so I can not use that sequence for another function.
If you changed that, you would find it cumbersome to use any terminal application, because all of the POSIX-like systems use "newline" for ending lines. An ASCII carriage return ^M is normally translated into a newline (which happens to be encoded as ASCII line-feed ^J). If you run stty -a on your terminal you may notice something like this:
~ (4) stty -a
speed 38400 baud; 40 rows; 80 columns;
lflags: icanon isig iexten echo echoe echok echoke -echonl echoctl
-echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
-extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff -ixany -imaxbel -iutf8
-ignbrk brkint -inpck -ignpar -parmrk
oflags: opost onlcr -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
-dtrflow -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
eol2 = <undef>; erase = ^?; intr = ^C; kill = ^U; lnext = ^V;
min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T;
stop = ^S; susp = ^Z; time = 0; werase = ^W;
The icrnl says that carriage-return is mapped to newline. So... if you break your return key, you could type control/M or control/J every time you want a newline. Most people prefer just pressing one key for that purpose.

Can't type 'a' symbol in terminal

I got into a strange behaviour of my terminal. Both iTerm and basic terminal on my OS X don't work. I can only type 'A' instead of 'a', but not the 'a' letter. If I try bash --noediting then I can type 'a' but it's very uncomfortable to use. I checked my ~/.bashrc, ~/.bash_profile and did't find anything that seemed strange for me. Could anyone help me?
Any feedback appreciated.
Most likely you've somehow introduced a readline binding for a.
As a first step, try this: (The grep argument is $"a", but you can't type that :) )
bind -p | grep $'"\x61"'
It should print this:
"a": self-insert
If it does, then my guess is wrong, and you'll need to look elsewhere. If it doesn't, then you need to fix it, which you can do like this:
bind $'"\x61"':self-insert
Now you need to find where in your bash start-up files the incorrect bind command is. I'd start by grepping for bind. It may well be in a file sourced from one of those files. Good luck.
You should also check the file ~/.inputrc which is used by the readline library to initialize it's bindings.
If the letter a has been mapped to one of the control characters, you can get some funny effects. Try stty -a, except that you'll probably need to type:
s, t, t, y, , -, Control-V, a
to get the -a to the command. This should show you something like:
speed 9600 baud; 65 rows; 135 columns;
lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl
-echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
-extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel iutf8
-ignbrk brkint -inpck -ignpar -parmrk
oflags: opost onlcr -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
-dtrflow -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
eol2 = <undef>; erase = ^?; intr = ^C; kill = ^X; lnext = ^V;
min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T;
stop = ^S; susp = ^Z; time = 0; werase = ^W;
except that if my suspicion is correct, one of the cchars values is a.

Serial Port Hangs

I have a usb to serial FTDI adaptor connected to my mac. I am able to use the command:
screen /dev/tty.usbserial-A601L9OC
This opens a serial terminal for the port and everything works fine. But when I try to send characters to the serial port via the command:
root# echo 'a' > /dev/tty.usbserial-A601L9OC
the command hangs and nothing is ever sent. A similar thing happens when I try to connect to it in a c program. The program hangs trying to open the serial port:
int fd = open("/dev/tty.usbserial-A601L9OC", O_RDWR | O_NOCTTY | O_SYNC);
When I run stty on the port it prints:
root# stty -f /dev/tty.usbserial-A601L9OC
speed 9600 baud;
lflags: -icanon -isig -iexten -echo
iflags: -icrnl -ixon -ixany -imaxbel -brkint
oflags: -opost -onlcr -oxtabs
cflags: cs8 -parenb
which looks correct. Does anybody have an ideas as to why these commands hang and never send when connecting to the serial port yet screen works just fine? Any help will be appreciated.
Update: The results of getting info from stty
bash-3.2# stty -a -f /dev/tty.usbserial-A601L9OC
speed 9600 baud; 0 rows; 0 columns;
lflags: -icanon -isig -iexten -echo -echoe -echok -echoke -echonl
-echoctl -echoprt -altwerase -noflsh -tostop -flusho -pendin
-nokerninfo -extproc
iflags: -istrip -icrnl -inlcr -igncr -ixon -ixoff -ixany -imaxbel -iutf8
-ignbrk -brkint -inpck -ignpar -parmrk
oflags: -opost -onlcr -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
-dtrflow -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
eol2 = <undef>; erase = ^?; intr = ^C; kill = ^U; lnext = ^V;
min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T;
stop = ^S; susp = ^Z; time = 0; werase = ^W;
Use the device /dev/cu.usbserial-A601L9OC instead, and set the speed to 9600 baud also. Here's an example from Magnus' macrumor post:
strcpy(bsdPath, "/dev/cu.usbserial-A601L9OC");
fileDescriptor = open(bsdPath, O_RDWR);
if (-1 == fileDescriptor)
{
return EX_IOERR;
}
struct termios theTermios;
memset(&theTermios, 0, sizeof(struct termios));
cfmakeraw(&theTermios);
cfsetspeed(&theTermios, 9600);
theTermios.c_cflag = CREAD | CLOCAL; // turn on READ and ignore modem control lines
theTermios.c_cflag |= CS8;
theTermios.c_cc[VMIN] = 0;
theTermios.c_cc[VTIME] = 10; // 1 sec timeout
int ret = ioctl(fileDescriptor, TIOCSETA, &theTermios);
ret = read(fileDescriptor, &c, 1);
Use O_NONBLOCK otherwise the open waits for Carrier Detect.

Resources