# How to react to a key press in rjs file?

**URL:** <https://www.ruby-forum.com/t/how-to-react-to-a-key-press-in-rjs-file/152060>\
**Category:** Rails\
**Created:** [October 29, 2008, 4:01pm UTC](https://www.ruby-forum.com/t/how-to-react-to-a-key-press-in-rjs-file/152060 "2008-10-29T16:01:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![christopher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/439d5e/32.png) [@christopher](https://www.ruby-forum.com/u/christopher)\
**Post date:** [October 29, 2008, 4:01pm UTC](https://www.ruby-forum.com/t/how-to-react-to-a-key-press-in-rjs-file/152060/1 "2008-10-29T16:01:40Z")

</div>

Hi everybody,

I’m a rails beginner and I’m trying to figure out how to react to a  
keyboard press in an rjs-file and then do some stuff to the page. It  
should go something like this:

if @correct  
#do something  
#wait for the user to press any key  
#do something  
end  
end

Does anybody know how to do this?

Thanks in advance!  
Christopher

---

<div class="post-metadata">

**Author:** ![christopher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/439d5e/32.png) [@christopher](https://www.ruby-forum.com/u/christopher)\
**Post date:** [October 29, 2008, 4:08pm UTC](https://www.ruby-forum.com/t/how-to-react-to-a-key-press-in-rjs-file/152060/2 "2008-10-29T16:08:42Z")

</div>

On 29 Oct 2008, at 14:40, Christopher wrote:

> #do something  
> end  
> end
> 
> Does anybody know how to do this?

That’s not really how event handling is done in javascript. you would  
normally attach an event handler to some page object rather than sit  
and wait for an event to happen.

Fred
