Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 03 Sep 2014, 03:59
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
Detecting keyboard state from shell
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [4 Posts]  
Author Message
jamesbond

Joined: 26 Feb 2007
Posts: 2134
Location: The Blue Marble

PostPosted: Tue 14 May 2013, 07:58    Post subject:  Detecting keyboard state from shell  

Barry discussed the needs here (second comment): http://bkhome.org/blog2/?viewDetailed=00238. So I went googling for a while, found the answer here: http://stackoverflow.com/questions/3649874/how-to-get-keyboard-state-in-linux and tidy it up a little bit, as attached.

Usage: kbstate key [devpath]
Returns: 0 if key is pressed, 1 otherwise, 255 for errors.

"key" is either lshift, rshift, lalt, ralt, lctrl, or rctrl (that's left/right shifts, left/right alts, left/right controls) in English keyboard, not sure the equivalents in others. If you hack the source you can easily check for other keys too.

"devpath" is the path to the Linux's keyboard event device. The default value is "/dev/input/by-path/platform-i8042-serio-0-event-kbd" (that is, the built-in PS/2 keyboard) but most of the time you would specify /dev/input/event5 or something. Scan /proc/bus/input/devices, find a device whose handlers is "kbd", and you know which /dev/input/eventXXX you need to specify.
If you need to test multiple keyboards (PS/2, USB, etc) you will need to call kbstate multiple times, one for each devpath.

To compile, just use your favorite compiler like this: "gcc -o kbstate kbstate.c". I've got it compiled statically under 64-bit musl, 32-bit and 64-bit aboriginal cross compiler.

Enjoy.

cheers!

EDIT: add 32-bit and 64-bit static binaries for convenience. Should work in all puppies, 32 and 64-bit.
kbstate.gz
Description  64-bit static executable (with musl). Gunzip first.
gz

 Download 
Filename  kbstate.gz 
Filesize  2.26 KB 
Downloaded  161 Time(s) 
kbstate32.gz
Description  32-bit static executable. Gunzip first.
gz

 Download 
Filename  kbstate32.gz 
Filesize  3.49 KB 
Downloaded  162 Time(s) 
kbstate.c.gz
Description  Source. Gunzip first.
gz

 Download 
Filename  kbstate.c.gz 
Filesize  988 Bytes 
Downloaded  162 Time(s) 

_________________
Fatdog64, Slacko and Puppeee user. Puppy user since 2.13.
Contributed Fatdog64 packages thread

Last edited by jamesbond on Tue 14 May 2013, 12:02; edited 1 time in total
Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 11034
Location: Arizona USA

PostPosted: Tue 14 May 2013, 08:35    Post subject:  

Puppy already has xev, which may not be useful in the same way.
Back to top
View user's profile Send private message 
jamesbond

Joined: 26 Feb 2007
Posts: 2134
Location: The Blue Marble

PostPosted: Tue 14 May 2013, 08:43    Post subject:  

xev requires X, this one runs in console and is meant to be used in initrd.
_________________
Fatdog64, Slacko and Puppeee user. Puppy user since 2.13.
Contributed Fatdog64 packages thread
Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 11034
Location: Arizona USA

PostPosted: Tue 14 May 2013, 11:26    Post subject:  

Ah. Thank you for clearing that up. Smile
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [4 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Cutting edge
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0497s ][ Queries: 13 (0.0085s) ][ GZIP on ]