Sponsored Content
Top Forums Shell Programming and Scripting sh: Detect key (CTRL/SHIFT/CAPS LOCK) state? Post 302487441 by Ilja on Wednesday 12th of January 2011 12:48:22 PM
Old 01-12-2011
Quote:
Originally Posted by methyl
Clearly /dev/input/event3 is not a text file and therefore not suitable for reading with a Shell read. In fact there is little of interest to Shell programmers under /dev. (Yep I know about /dev/null etc.).
Be very very careful in /dev - it is remarkably easy to destroy your system.

What is the output from:
Code:
ls -lad /dev/input/event3
file /dev/input/event3

(Googling the device suggests that it might be a keyboard device on some versions of Linux - a fact of little use to Shell programmers).

What Operating System and version are you running?
What Shell are you running?
What are you trying to do? Can you explain the Project in words just in case there is a stock solution?


There will be kernel driver software between Shell and a keyboard.
If you have "bash" there is a Shell raw "read" with a timeout but even then it will not register keys like ctrl and shift as characters. Reading characters in a tight loop without timeout is CPU-intensive.

A common way to modify the behaviour of a cleverly designed running Shell script is to create a flag file or to use a Shell "trap" to react to a keyboard control code or signal.


What is an "initramfs script", what does it do, and why would you want to interrupt it?

Is it like this:
initrd - Wikipedia, the free encyclopedia

What runstate are you in while this script is running?
Now, here's my problem. I'm trying to unlock my encrypted system disk in Ubuntu 10.10. Sometimes I want to enter the passphrase via SSH and sometimes locally. Here's the piece of code that needs to be modified.
Code:
if [ -x /bin/plymouth ] && plymouth --ping; then
  cryptkeyscript="plymouth ask-for-password --prompt"
  cryptkey=$(echo -e "$cryptkey")
else
  cryptkeyscript="/lib/cryptsetup/askpass"
fi

I need the script to run the first case if I want to enter the passphrase via the local keyboard, and run the second case if I want to enter the passphrase via SSH.
Code:
if [ -x /bin/plymouth ] && plymouth --ping && #I'm at the keyboard#; then
  cryptkeyscript="plymouth ask-for-password --prompt"
  cryptkey=$(echo -e "$cryptkey")
else
  cryptkeyscript="/lib/cryptsetup/askpass"
fi

So, how do I notify the computer that I am at the keyboard? By pressing a key, perhaps.
 

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
SHLOCK(1)						      General Commands Manual							 SHLOCK(1)

NAME
       shlock - create lock files for use in shell scripts

SYNOPSIS
       shlock -p pid -f name [ -b ] [ -u ] [ -c ]

DESCRIPTION
       Shlock  tries  to  create  a  lock  file named name and write the process ID pid into it.  If the file already exists, shlock will read the
       process ID from the file and test to see if the process is currently running.  If the process exists, then the file will not be created.

       Shlock exits with a zero status if it was able to create the lock file, or non-zero if the file refers to currently-active process.

OPTIONS
       -b     Process IDs are normally read and written in ASCII.  If the ``-b'' flag is used, then they will be written as  a	binary	int.   For
	      compatibility with other systems, the ``-u'' flag is accepted as a synonym for ``-b'' since binary locks are used by many UUCP pack-
	      ages.

       -c     If the ``-c'' flag is used, then shlock will not create a lock file, but will instead use the file to see if the	lock  is  held	by
	      another  program.   If  the  lock  is  valid, the program will exit with a non-zero status; if the lock is not valid (i.e., invoking
	      shlock without the flag would have succeeded), then the program will exit with a zero status.

EXAMPLES
       The following example shows how shlock would be used within a shell script:
	      LOCK=/var/run/innd/LOCK.send
	      trap 'rm -f ${LOCK} ; exit 1' 1 2 3 15
	      if shlock -p $$ -f ${LOCK} ; then
		  # Do appropriate work
	      else
		  echo Locked by `cat ${LOCK}`
	      fi

HISTORY
       Written by Rich $alz <rsalz@uunet.uu.net> after a description of HDB UUCP locking given by Peter Honeyman.  This  is  revision  1.9,  dated
       1996/10/29.

																	 SHLOCK(1)
All times are GMT -4. The time now is 01:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy