LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 03-31-2008, 12:07 AM   #1
craftybytes
Member
 
Registered: Jan 2006
Location: Killarney, QLD Australia
Distribution: Mepis 3.4-3; Puppy 2.12; WinXP Pro (rarely)
Posts: 54

Rep: Reputation: 15
Bash & Xdialog - how to code to recognize ENTER key on keyboard.?


Hi all..

Bash scripting query again..

1)
Say I have the following snippet in a Bash script:

Code:
Xdialog --screen-center --title "CONFIRM..!" --yesno "Are you sure you want to overwrite existing file?" 6 60
 case $? in
   0)
     echo "1" > $FIL8;;
   1)
     rm -f $FIL3;
     rm -f $FIL7;
     rerun1;
     ;;
   255)
     rm -f $FIL3;
     rm -f $FIL7;
     rerun;
     ;;
 esac
what do I need to add to the 'case' statements to check for the "ENTER" key on the keyboard being pressed..?

or do I need to use something like 'grep' or 'sed' to do this..?

If so how..?

2)
There is also another snippet of bash script that I would like to add this "ENTER" key code to as well:

Code:
Xdialog --screen-center --title "$Key Input" --inputbox "The input should be an alphanumeric string
between a minimum 8 to a maximum 48 characters..
Can contain uppercase and lowercase letters and numbers..

Please enter your input: " 20 58 2> /root/.tmp1/.inputbox.tmp.$$
retval=$?
input=`cat /root/.tmp1/.inputbox.tmp.$$`
touch $input
rm -f /root/.tmp1/.inputbox.tmp.$$
 if [ "$retval" -eq 1 ];then
  rerun
 else
  echo "entry - OK"
 fi
What code do I need to add to the 'if' statement to check for the "ENTER" key being pressed on the keyboard..?

or do I need to use 'grep' or 'sed' for this..?

If so how..?

The reason for this is - I have coded for an "OK" button in the Xdialog boxes - but I would like to allow for the user to use the "ENTER" key on the keyboard to do the exact same thing as clicking on the "OK" button as well..!!

TIA.

crafty.
.
.
 
Old 03-31-2008, 05:59 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,988
Blog Entries: 54

Rep: Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743
In your case you don't need to AFAIK.
0) Dialog apps rely on the user selecting the right button and then pressing enter to signify their choice and
1) since you're using a graphical interface your script isn't exposed to receive enters and
2) at least with Zenity the selection can only be one of two buttons, it can't be anything else so you wouldn't be able to send an enter unless you run something that intercepts the keyboard (and you don't want to do that) and
3) your users will be baffled by the inconsistency with other apps that don't exhibit that behaviour.
You only need to work with the exit value, makes things easier for you and your users.
 
Old 03-31-2008, 12:06 PM   #3
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 230Reputation: 230Reputation: 230
In other words, pressing "Enter" is already being recognized -- it's the same as clicking on the currently selected button.

Why would you want to change a default behavior that is consistent w/ the vast majority of GUI apps., across desktop environments & even OS's?

By chance, did you inherit the maintenance of this code?
 
Old 04-01-2008, 01:02 AM   #4
craftybytes
Member
 
Registered: Jan 2006
Location: Killarney, QLD Australia
Distribution: Mepis 3.4-3; Puppy 2.12; WinXP Pro (rarely)
Posts: 54

Original Poster
Rep: Reputation: 15
Thanks for the replies..

As shown - for the 'case' statements - 0) = covers the OK button; 1) = covers the CANCEL button; 255) = covers the 'close' button for the box window..

And in a fashion - the same for the 'if/then' grouping..

Just thought that there may have been ways to add in the extra for possible ENTER key usage as well..

@archtoad6 -
Quote:
In other words, pressing "Enter" is already being recognized
Well in the case of my code - it actually isn't recognized - no matter how many times the ENTER key is pressed, there is no execution of the input - ONLY clicking on the OK button does the job..

Yes and no - I actually wrote the script - so I'll have to maintain it as well..

Anyway - the script works well and does do what it was designed for - just thought that there might have been room for some slight improvement - especially towards those who prefer to use the keyboard more than a mouse..

Much appreciated for the replies though..

crafty.
.
.
 
Old 04-01-2008, 07:25 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,988
Blog Entries: 54

Rep: Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743Reputation: 2743
Quote:
Originally Posted by craftybytes View Post
Well in the case of my code - it actually isn't recognized - no matter how many times the ENTER key is pressed, there is no execution of the input - ONLY clicking on the OK button does the job..
X11/Xorg, DEs and WMs adhere to certain standards so most of them behave predictably when it comes to selecting windows in the foreground, recognising "OK" and "Cancel" buttons and using keyboard events to work those. Being more thorough analysing and describing the env and code you're working in might help us help you.
 
Old 04-01-2008, 10:15 AM   #6
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 230Reputation: 230Reputation: 230
craftybytes,

What was your distro/DE environment?

(I was/am using MEPIS 6.0, KDE 3.5.3)

Last edited by archtoad6; 04-03-2008 at 05:31 AM. Reason: typo
 
Old 04-03-2008, 01:00 AM   #7
craftybytes
Member
 
Registered: Jan 2006
Location: Killarney, QLD Australia
Distribution: Mepis 3.4-3; Puppy 2.12; WinXP Pro (rarely)
Posts: 54

Original Poster
Rep: Reputation: 15
.
Distro & DE environment =

Puppy Linux v2.15CE (kernel 2.6.18.1); & iceWM & ROX..!!

But my scripts are mainly in Bash & using Xdialog + a couple of 'yaf-splash' boxes..

So should work in ANY linux distro if got Bash & Xdialog..

Anyway - as I said previously - my scripts are working well and doing what I expected..

I'm of the belief though that - a little "positive" tweaking here & there does not go astray..

Thanks for the interest..

crafty.
.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Xdialog/Bash Help, Please. br00tal Slackware 8 12-03-2007 02:42 PM
How to have mouse button act as "enter" key in bash xmrkite Linux - Software 7 10-17-2006 05:51 PM
Bash: how to read <enter> key linmix Programming 3 12-02-2005 04:38 PM
PS2 keyboard doesn't work after the "Enter" key is used gonefishing Suse/Novell 1 11-06-2004 10:02 PM
Teach Linux to recognize keyboard key jpbarto Linux - Hardware 2 05-08-2003 07:49 AM


All times are GMT -5. The time now is 09:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration