Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created May 23, 2014 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/b922bd416d78a8f620e3 to your computer and use it in GitHub Desktop.
Save havenwood/b922bd416d78a8f620e3 to your computer and use it in GitHub Desktop.
Detect an arrow key press.
require 'io/console'
ARROWS = {"[A"=>:up, "[B"=>:down, "[C"=>:right, "[D"=>:left}
char = STDIN.getch
ARROWS[STDIN.read_nonblock(2)] if char == "\e"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment