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
glutKeyboardUpFunc(3GLUT)					       GLUT						 glutKeyboardUpFunc(3GLUT)

NAME
glutKeyboardUpFunc - sets the keyboard up (key release) callback for the current window. SYNTAX
void glutKeyboardUpFunc(void (*func)(unsigned char key, int x, int y)); ARGUMENTS
func The new keyboard up callback function. DESCRIPTION
glutKeyboardFunc sets the keyboard up (key release) callback for the current window. When a user types into the window, each key release matching an ASCII character will generate a keyboard up callback. The key callback parameter is the generated ASCII character. The state of modifier keys such as Shift cannot be determined directly; their only effect will be on the returned ASCII data. The x and y callback parameters indicate the mouse location in window relative coordinates when the key was pressed. When a new window is created, no keyboard callback is initially registered, and ASCII key strokes in the window are ignored. Passing NULL to glutKeyboardFunc disables the generation of keyboard callbacks. During a keyboard up callback, glutGetModifiers may be called to determine the state of modifier keys when the keystroke generating the callback occurred. To avoid the reporting of key release/press pairs due to auto repeat, use glutIgnoreKeyRepeat to ignore auto repeated keystrokes. There is no guarantee that the keyboard press callback will match the exact ASCII character as the keyboard up callback. For example, the key down may be for a lowercase b, but the key release may report an uppercase B if the shift state has changed. The same applies to sym- bols and control characters. The precise behavior is window system dependent. Use glutSpecialUpFunc for a means to detect non-ASCII key releases. SEE ALSO
glutKeyboardFunc, glutSpecialUpFunc, glutSpecialFunc, glutCreateWindow, glutMouseFunc, glutSpaceballButtonFunc, glutButtonBoxFunc, glut- TabletButtonFunc, glutGetModifiers, glutIgnoreKeyRepeat AUTHOR
Mark J. Kilgard (mjk@nvidia.com) GLUT
3.7 glutKeyboardUpFunc(3GLUT)
All times are GMT -4. The time now is 11:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy