Sponsored Content
Top Forums Shell Programming and Scripting sh: Detect key (CTRL/SHIFT/CAPS LOCK) state? Post 302487177 by Ilja on Tuesday 11th of January 2011 03:41:38 PM
Old 01-11-2011
So, I made this code, but it's not working and I have no idea why.
Code:
#!/bin/sh

read VAR < /dev/input/event3

if [ -n "${VAR}" ]; then
  echo "Key pressed"
else
  echo "No key pressed"
fi

If I do something like 'cat /dev/input/event3' and press some keys, I get all sorts of garbage on the screen, so I know I can get output from the keyboard, but when I run the script '$VAR' stays empty. If I use a regular non-empty file or some other device, (like the hard disk) the script works.

I'm totally stumped.Smilie Any help would be much appreciated.

Last edited by Ilja; 01-11-2011 at 04:52 PM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Disabling ctrl-Z key inside shell script

Hi I have tried to disable the CTRL-Z key inside a shell(sh) script using the command trap "`echo "Ctrl-Z key disabled"`" 20But I am not able to exit from the script after pressing CTRL-Z key. How to proceed this? Need reply soon (11 Replies)
Discussion started by: suganthic
11 Replies

2. Shell Programming and Scripting

How to delete ctrl key values in a given string?

Hi all, My query is... in the runtime, you are getting any input string. Unfortunately, you have pressed some ctrl keys or esc keys or arrow keys while typing input string. You can get the input value like that... input string as welcome^ So ,I want to remove those unwanted keys... (4 Replies)
Discussion started by: balan_mca
4 Replies

3. Red Hat

Caps lock dtterm

Hello, We are having a problem with running dtterm off a RHEL server. Logging into an HP-UX server from a RHEL 5.1 desktop, setting DISPLAY and running dtterm, the caps lock does not work. We have been playing with xmodmap & stty but to no avail. Any help appreciated. mgb (1 Reply)
Discussion started by: mgb
1 Replies

4. HP-UX

Caps lock dtterm

Hello, We are having a problem with running dtterm off a RHEL server. Logging into an HP-UX server from a RHEL 5.1 desktop, setting DISPLAY and running dtterm, the caps lock does not work. We have been playing with xmodmap & stty but to no avail. Any help appreciated. mgb (7 Replies)
Discussion started by: mgb
7 Replies

5. Shell Programming and Scripting

How to issue ctrl+D and enter key

My problem is that i have to connect Linux server. I can connect it with SSH but because of the software of the Linux server, i need to press enter and after ctrl+D. Therefore, I need to write a script that should press enter and ctrl+D. How can i write it in KSH shell script. HELP ME! (7 Replies)
Discussion started by: fozay
7 Replies

6. UNIX for Advanced & Expert Users

Set Caps and Num lock from within X?

Hello, Not sure if this is the right place to post it but.. I have a requirement to set Caps lock and/or Num lock on and off via a Cron job. Now I have working scripts that do the job, but as soon as X starts up the jobs no longer run (well they appear to, but Caps lock and Num lock do not... (0 Replies)
Discussion started by: autotuner
0 Replies

7. UNIX for Dummies Questions & Answers

Caps lock problem

hi all this s quite a foolish problem. I seem to hav pressed some keys s.t in unix, my letters are comin in caps and with caps lock on, i am getting lowercase letters. :o Pls help. Also is there any reference or manual where i can check in case such problems arrise? thanx in advance curiosity (4 Replies)
Discussion started by: curiosity
4 Replies

8. Shell Programming and Scripting

How to detect key press in cgi shell script?

I want to detect key pressed in my .cgi web page, but it does not work even I found the code in other web site. My code is : #!/bin/sh #================================================= # PATH defination # ================================================... (2 Replies)
Discussion started by: Shuinvy
2 Replies

9. Shell Programming and Scripting

Generate all possible word with caps and no caps

With use of sed/awk, how can I print all possible combinations of a word with caps/non-caps. Eg Applying operation on "cap" should generate output as follows. cap CAP Cap cAp caP CAp cAP CaP (12 Replies)
Discussion started by: anil510
12 Replies
keytest(1)							   Linux Manual 							keytest(1)

NAME
keytest - reports names of pressed keys SYNOPSIS
keytest [input_device_name] DESCRIPTION
keytest ESE Key Daemon is a multimedia keyboard driver for Linux. With the 2.6 kernel series it can also handle remote controls, as they are presented as keyboards. No kernel patch is required. It is a userspace program that pools /dev/input/event? interfaces for incoming keyboard key presses. OPTIONS
Options: input_device_name input (event) device; if given turns off autodetection of 1st keyboard device FILES
/usr/sbin/esekeyd - main binary (daemon) /usr/bin/keytest - program that reports names of pressed keys /usr/bin/learnkeys - config file generator /usr/share/man/man1/{esekeyd,keytest,learnkeys}.1(.gz) - manual pages SEE ALSO
esekeyd(1), learnkeys(1) BUGS
See the file TODO in the distribution for information on what remains to be done. If you want to report a problem with the program, please send mail to this address: <krzysztof@burghardt.pl>. Provide a detailed description of the bug, the version of the program you are running (run keytest without any parameters to display this information), the operating system you are running the program on and if the program crashes, I would appreciate a stack trace. AUTHOR
This program was written by Krzysztof Burghardt <krzysztof@burghardt.pl> and may be freely distributed under the terms of the GNU General Public License. There is ABSOLUTELY NO WARRANTY for this program. Linux Utilities 21 Feb 2006 keytest(1)
All times are GMT -4. The time now is 02:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy