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="Dinosaur_Weirdo" data-source="post: 1779072" data-attributes="member: 397195"><p>Not sure when this was changed but for anyone who found this thread ages after the original post (like me), the read command can't have a timeout of <1 second. Which means that with this solution, you would have to wait two seconds before a character was detected. Luckily, I have a fix.</p><p>[CODE]</p><p>#!/bin/bash</p><p>echo "Press the UP arrow."</p><p>read -rsn1 esc</p><p>if [ $esc == $'\033' ]; then</p><p> read -sn1 bra</p><p> read -sn1 typ</p><p>fi</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></blockquote><p></p>
[QUOTE="Dinosaur_Weirdo, post: 1779072, member: 397195"] Not sure when this was changed but for anyone who found this thread ages after the original post (like me), the read command can't have a timeout of <1 second. Which means that with this solution, you would have to wait two seconds before a character was detected. Luckily, I have a fix. [CODE] #!/bin/bash echo "Press the UP arrow." read -rsn1 esc if [ $esc == $'\033' ]; then read -sn1 bra read -sn1 typ fi 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] [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Reading arrow keys in terminal (partial success!)
Top