How to detect a single key without using a terminal?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

How to detect a single key without using a terminal?

#1 Post by rhadon »

Hi everybody,

I want to detect a single key by a script and found two possible solutions (e.g. with key = "z"):

Code: Select all

char=''	
read -n1 char > /dev/null
if [ "$char" = "z" ] ; then 
...
fi
or

Code: Select all

stty raw -echo
char=`dd bs=1 count=1 2>/dev/null`
if [ "$char" = "z" ] ; then 
...
fi
stty -raw echo
The big problem, it only works if I run the script from a terminal, which I don't want. It should run in the background.

So, is it a problem of maybe I/O redirection or am I barking up the wrong tree?

hopefully,
Rolf
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#2 Post by greengeek »

SFR initially used xbindkeys for a similar purpose, then changed that to using a special script (which he called "detect_key") in this topic here:
http://murga-linux.com/puppy/viewtopic.php?t=87418

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#3 Post by rhadon »

I'll take a look.

Thanks greengeek,

Rolf
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#4 Post by Karl Godt »

Ahh, radon finally wants to make mouse trap trojans with keylogging ability :P

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#5 Post by rhadon »

Ahh, radon finally wants to make mouse trap trojans with keylogging ability
Not exactly Karl, but near the mark :lol:

Rolf[/quote]
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

#6 Post by jamesbond »

Look at here http://jamesbond3142.no-ip.org/wiki/mai ... ootmenu.gz and check the "event handling" section. You need evtest for this to work.

cheers!
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#7 Post by Karl Godt »

Ha ! Finally found acpid v1 while searching for evtest .. remembered it from acpid v2 :

http://sourceforge.net/projects/acpid2/files/
http://sourceforge.net/projects/acpid2/ ... 2/download

Works pretty good !

Post Reply