User input - get keystrokes (arrow keys + shift)

M

Marc Heiler

Hello.

I am trying to find out how to do a specific action / call a method if a
user presses the SHIFT key and an arrow key. (Two keys pressed together)

I use this for a very simple program, a pseudo shell. Like, "cd
/home/marcelle" allows the user to enter the /home/marcelle directory
via Dir.chdir.

Now, if SHIFT + left arrow key is pressed, I want to be able to go back
one directory, i.e. to "/home". (To simplify, the SHIFT key could be
omitted and just the arrow key used)

My problem is that I do not know how I can intercept or even act on this
at all. It seems so far that mostly, via $stdin.gets, you must wait for
ENTER to be pressed. Logically, if a user presses shift + left arrow
key, there won't be any enter here as part of the input.

How can I get the information that the arrow key was pressed?

Is there a way in Ruby to do a specific action when:

- any single key is input
- any combination is input (i.e. shift + another character)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top