Sponsored Content
Top Forums Shell Programming and Scripting how can i know the pressed key is arrowup? Post 302492603 by homeboy on Tuesday 1st of February 2011 01:51:37 AM
Old 02-01-2011
how can i know the pressed key is arrowup?

Hi all,
I need to know how to test a pressed key is arrowup or arrowdown and etc..
I found that the "echo" won't print anything if i enter the arrowup in the below code:
Code:
read 
echo "you pressed $REPLY"

Then i find a way to achieve my goal.
Code:
  1 #! /bin/bash
  2 
  3 ARROWUP='\[A'
  4 read
  5 echo $REPLY | grep -q $UP
  6 if [ $? -eq 0 ];then
  7    echo "you pressed arrowup"
  8 fi

problem is where can i find "ARROWUP" is shown as \[A because in my terminal the arrowup key is shown as [[A and i'm afraid i won't remember that someday.Any command to show that?
 

9 More Discussions You Might Find Interesting

1. Programming

know what key is pressed

hi i´m making a program, and i would like to know how can i know what key was pressed. i'm using Sun5.7 and C. is there a keypress/keypressed function in C? how can i know recognize the keys (enter, tab, shift, etc.)? can i recognize two keys ? (shift+A, ctrl+C, etc) any idea.. thanks (4 Replies)
Discussion started by: DebianJ
4 Replies

2. Shell Programming and Scripting

How to identify whether the return key is pressed ??

I want my program(ksh) to execute further only if the return key is pressed. Please help. i have already tried "\n", "\r", "^M" . Thanks in advance (2 Replies)
Discussion started by: AiK
2 Replies

3. UNIX for Dummies Questions & Answers

screen blinks when escape key is pressed

hi folks, i am using sun solaris, when i press escape key in putty/netterm screen will blink for a second, plese let me know where this setting is done by my admin, what i feel is my admin must have set some control key for this so that screen will refresh each time i press escape key. please let... (1 Reply)
Discussion started by: sudheer157
1 Replies

4. Shell Programming and Scripting

detect F5 is pressed

Hello friends, I want to write a shell script in bash shell . Working for the script is to detect any key pressed and disply on screen as "you have pressed: " For example if user pressed F5 then a messaged has to be displayed as "you have pressed F5. Thank you. (4 Replies)
Discussion started by: pradeepreddy
4 Replies

5. Shell Programming and Scripting

how can i do some action when 'ctrl+d' is pressed

hi Gurus, please why is this happening: when i run this: #!/bin/bash declare -a name declare -a ph declare -a eid r=0; c=1; i=1; n=; echo " name phone email_id" while : do #if ; then #break; #else echo -n "field $i:"; read name ph eid; let "i++"; ... (5 Replies)
Discussion started by: tprayush
5 Replies

6. Shell Programming and Scripting

Wait given time unless key pressed

Hello everyone. I'm trying to create a script that waits a given amount of time unless a given key is pressed. I found a very useful thread here https://www.unix.com/shell-programming-scripting/59605-trap-key-press-script.html however, I cannot figure out a way of avoiding the keypress if the... (2 Replies)
Discussion started by: cue
2 Replies

7. Shell Programming and Scripting

Disable Enter key to be pressed

Hi Experts, I have a script in which I want to disable the "Enter" key press. Actually my script executes some process in background. So, till that background process is running, I don't want "Enter" key to be pressed by user. Is this can be achieved using trap command? (6 Replies)
Discussion started by: R0H0N
6 Replies

8. Shell Programming and Scripting

Get Rid ^C when pressed Ctrl-C

How do i get rid of the ^C when i pressed Ctrl-C? (7 Replies)
Discussion started by: vietrice
7 Replies

9. Ubuntu

Pressed/Net Install 12.04 LTS

So I mounted a 12.04 LTS ISO, exported it via apache. Goy my netinstall files in place. Pointed Foreman to my install media the Preseed config files run. Life is good. Server comes up, I run apt-get update and blam: : Failed to fetch... (0 Replies)
Discussion started by: general_lee
0 Replies
readkey(3alleg4)						  Allegro manual						  readkey(3alleg4)

NAME
readkey - Returns the next character from the keyboard buffer. Allegro game programming library. SYNOPSIS
#include <allegro.h> int readkey(); DESCRIPTION
Returns the next character from the keyboard buffer, in ASCII format. If the buffer is empty, it waits until a key is pressed. You can see if there are queued keypresses with keypressed(). The low byte of the return value contains the ASCII code of the key, and the high byte the scancode. The scancode remains the same whatever the state of the shift, ctrl and alt keys, while the ASCII code is affected by shift and ctrl in the normal way (shift changes case, ctrl+letter gives the position of that letter in the alphabet, eg. ctrl+A = 1, ctrl+B = 2, etc). Pressing alt+key returns only the scan- code, with a zero ASCII code in the low byte. For example: int val; ... val = readkey(); if ((val & 0xff) == 'd') /* by ASCII code */ allegro_message("You pressed 'd' "); if ((val >> 8) == KEY_SPACE) /* by scancode */ allegro_message("You pressed Space "); if ((val & 0xff) == 3) /* ctrl+letter */ allegro_message("You pressed Control+C "); if (val == (KEY_X << 8)) /* alt+letter */ allegro_message("You pressed Alt+X "); This function cannot return character values greater than 255. If you need to read Unicode input, use ureadkey() instead. SEE ALSO
install_keyboard(3alleg4), ureadkey(3alleg4), keypressed(3alleg4), clear_keybuf(3alleg4), simulate_keypress(3alleg4) Allegro version 4.4.2 readkey(3alleg4)
All times are GMT -4. The time now is 05:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy