# How to create keybinds?

**URL:** <https://www.ruby-forum.com/t/how-to-create-keybinds/191419>\
**Category:** Ruby\
**Created:** [July 12, 2010, 1:22pm UTC](https://www.ruby-forum.com/t/how-to-create-keybinds/191419 "2010-07-12T13:22:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![makire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@makire](https://www.ruby-forum.com/u/makire)\
**Post date:** [July 12, 2010, 1:22pm UTC](https://www.ruby-forum.com/t/how-to-create-keybinds/191419/1 "2010-07-12T13:22:23Z")

</div>

My Rubyknowledge is somewhat limited, so im in need of some help with  
the following dilemma…  
is there a way to create keybinds in ruby? In plain english, I want to  
be able to press f2 and run a rubyscript, how would I go about doing  
that?

---

<div class="post-metadata">

**Author:** ![makire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@makire](https://www.ruby-forum.com/u/makire)\
**Post date:** [July 12, 2010, 7:42pm UTC](https://www.ruby-forum.com/t/how-to-create-keybinds/191419/2 "2010-07-12T19:42:04Z")

</div>

On 7/12/10, Erik L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> My Rubyknowledge is somewhat limited, so im in need of some help with  
> the following dilemma…  
> is there a way to create keybinds in ruby? In plain english, I want to  
> be able to press f2 and run a rubyscript, how would I go about doing  
> that?

We need some more information to be able to help you. What environment  
or windowing toolkit are you working in? It’s certainly possible to  
create, say, a win32 program in ruby which (when it is in the  
foreground) responds to f2 by running a piece of ruby code. So, are  
you looking at writing a win32 program? tk? macos? gtk? What operating  
system are you using?

If you want to have a global mode keybinding that works no matter what  
program is in the foreground, you should try out AutoHotKey if you’re  
on windows. On other operating systems, I’m not sure what the  
equivalent would be, but there’s probably a way.

---

<div class="post-metadata">

**Author:** ![makire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@makire](https://www.ruby-forum.com/u/makire)\
**Post date:** [July 13, 2010, 7:44am UTC](https://www.ruby-forum.com/t/how-to-create-keybinds/191419/3 "2010-07-13T07:44:21Z")

</div>

Terribly sorry, We use a Ruby CLI interface for a javasystem running on  
Linux. What I really do need is a keypressed scanner of some sort… 🙂

---

<div class="post-metadata">

**Author:** ![makire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@makire](https://www.ruby-forum.com/u/makire)\
**Post date:** [July 13, 2010, 1:21pm UTC](https://www.ruby-forum.com/t/how-to-create-keybinds/191419/4 "2010-07-13T13:21:13Z")

</div>

Erik L. wrote:

> Terribly sorry, We use a Ruby CLI interface for a javasystem running on  
> Linux. What I really do need is a keypressed scanner of some sort… 🙂

If you want to map F2 (function keys, or alt/control keys) in your CLI  
interface, you really need an ncurses interface. You would typically  
have a loop checking for keypress and execute code based on key press.

To my knowledge, F2 cannot be bound without ncurses. If you are willing  
to live with normal menus and key selections, you should look _Highline_  
for building your CLI interface.
