# Unable to trap C-z, C-y, C-s and C-q

**URL:** <https://www.ruby-forum.com/t/unable-to-trap-c-z-c-y-c-s-and-c-q/150822>\
**Category:** Ruby\
**Created:** [October 13, 2008, 8:04pm UTC](https://www.ruby-forum.com/t/unable-to-trap-c-z-c-y-c-s-and-c-q/150822 "2008-10-13T20:04:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [October 13, 2008, 8:04pm UTC](https://www.ruby-forum.com/t/unable-to-trap-c-z-c-y-c-s-and-c-q/150822/1 "2008-10-13T20:04:19Z")

</div>

I need to trap ^Y, ^Z, ^S, ^Q etc in my app. Have googled a lot but  
unable to find anything.

Finally, I wrote a program and trapped all the signals.

1. Both C-z and C-y are trapped by SIGTSTP, but there is no key in  
getch() that they seem to trigger. Regardless of whether I use “SIG\_IGN”  
or print, my curses program aborts.

2. I am still not getting C-s and C-q. They are not caught by any  
signal.

My code inside a ncurses program is like this:

%w[ TSTP CONT ABRT HUP STOP PIPE IO IOT CHLD CLD ILL INFO QUIT SYS TRAP  
TTOU URG USR1 USR2 ].each { | alrm |  
#Signal.trap(“SIG#{alrm}”) { stdscr.mvprintw(17, 2, “%-40s” % "#{alrm}  
");

stdscr.refresh; } Signal.trap(“SIG#{alrm}”) { “SIG\_IGN” }

}

The commented line prints TSTP for both C-y and c-z and exits.  
The second exits.

Its not a terminal setting since I use Vim and alpine and they use these  
keys.

---

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [October 13, 2008, 9:17pm UTC](https://www.ruby-forum.com/t/unable-to-trap-c-z-c-y-c-s-and-c-q/150822/2 "2008-10-13T21:17:06Z")

</div>

Nit K. wrote:

> I need to trap ^Y, ^Z, ^S, ^Q etc in my app. Have googled a lot but  
> unable to find anything.

I finally found a workaround.  
On unix prompt did:

stty dsusp undef  
stty susp undef

Now my program catches c-y and c-z. However, is there are pure ruby way  
of doing this. googling reveals examples where “system stty …” is  
being used.

---

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [October 14, 2008, 12:25am UTC](https://www.ruby-forum.com/t/unable-to-trap-c-z-c-y-c-s-and-c-q/150822/3 "2008-10-14T00:25:45Z")

</div>

Nit K. wrote:

> Now my program catches c-y and c-z. However, is there are pure ruby way  
> of doing this. googling reveals examples where “system stty …” is  
> being used.

You can’t catch SIGKILL or SIGSTOP … has nothing to do with Ruby.

---

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [October 14, 2008, 1:25pm UTC](https://www.ruby-forum.com/t/unable-to-trap-c-z-c-y-c-s-and-c-q/150822/4 "2008-10-14T13:25:39Z")

</div>

probbably best to set the terminal to raw mode if this is unix as I  
suspect. [Ruby Quiz - Sokoban (#5)](http://www.rubyquiz.com/quiz5.html)  
shows an example of this. Search for the read\_char method or just  
for the string ‘raw’.

Ron.

---

<div class="post-metadata">

**Author:** ![sentinel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@sentinel](https://www.ruby-forum.com/u/sentinel)\
**Post date:** [October 14, 2008, 1:39pm UTC](https://www.ruby-forum.com/t/unable-to-trap-c-z-c-y-c-s-and-c-q/150822/5 "2008-10-14T13:39:48Z")

</div>

Ron F. wrote:

> probbably best to set the terminal to raw mode if this is unix as I  
> suspect. [Ruby Quiz - Sokoban (#5)](http://www.rubyquiz.com/quiz5.html)  
> shows an example of this. Search for the read\_char method or just  
> for the string ‘raw’.
> 
> Ron.

## Thanks to your tip, I just checked curses.raw(), and _there_ it is !!! Just what I needed.

## curses.raw() Enter raw mode. In raw mode, normal line buffering and processing of interrupt, quit, suspend, and flow control keys are turned off; characters are presented to curses input functions one by one.
