Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Reading arrow keys in terminal (partial success!)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Einstein32" data-source="post: 1591713" data-attributes="member: 328911"><p>Solution:</p><p>[CODE]</p><p>#!/bin/bash</p><p>echo "Press the UP arrow."</p><p>read -sn1 esc</p><p>read -sn1 -t 0.001 bra # "-t 0.001" is for robust-ness so pressing just any key wont put it into the wrong "read"</p><p>read -sn1 -t 0.001 typ</p><p>if [ "$esc$bra$typ" == $'\033'[A ]; then</p><p> echo "You pressed the UP arrow."</p><p>else</p><p> echo "You didn't press the up arrow, did you?"</p><p>fi</p><p>[/CODE]</p><p>If you have any questions, contact me. UP=A DOWN=B RIGHT=C LEFT=D</p></blockquote><p></p>
[QUOTE="Einstein32, post: 1591713, member: 328911"] Solution: [CODE] #!/bin/bash echo "Press the UP arrow." read -sn1 esc read -sn1 -t 0.001 bra # "-t 0.001" is for robust-ness so pressing just any key wont put it into the wrong "read" read -sn1 -t 0.001 typ if [ "$esc$bra$typ" == $'\033'[A ]; then echo "You pressed the UP arrow." else echo "You didn't press the up arrow, did you?" fi [/CODE] If you have any questions, contact me. UP=A DOWN=B RIGHT=C LEFT=D [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Reading arrow keys in terminal (partial success!)
Top