Created
May 23, 2014 21:09
-
-
Save havenwood/b922bd416d78a8f620e3 to your computer and use it in GitHub Desktop.
Detect an arrow key press.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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