nieters@eagle.crd.ge.com (coolbean) (02/20/91)
hi i have been RTFM'ing for long enough! time to post .... :-) the problem: i want to write a program which will tell me if a key has been pressed on the keyboard. i don't want to intercept the key or modify it, i just want to catch the "interrupt" and count it. ideally a blocking ioctl() or equivalent would be best but i can sit in a busy loop and poll until i see a key stroke, increment a counter, and continue. the platform: running on a Sun 4/490 or Sparcstation equivalent work so far: i've read kb(4M) a number of times and believe that it should be possible to tell when a keyboard is idle because it speaks of a #define IDLE 0x308 The keyboard is idle (no keys down) therefore, it should be possible to tell when it is NOT idle, right? /usr/include/sundev/kbd.h has some header comments that claim * When no physical keys are depressed, the keyboard transmits a keycode of * "IDLE" (7F hex), to indicate that. Thus, when the last key is released, * a keycode for its release is sent, then an IDLE. the following #defines are also contained in it #define IDLEKEY 0x7F /* Keyboard is idle; no keys down */ #define PRESSED 0x00 /* 0x80 bit off: key was pressed */ #define RELEASED 0x80 /* 0x80 bit on : key was released */ i've played with ioctl()'s to turn on LED's, keyclick, bell, find type of keyboard, etc. etc. etc. but i'm getting very confused with this key-press thing! if anyone has had experience doing this kind of thing, can you post a pointer to a solution?! any help is greatly appreciated. thanks in advance. --ed -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Edward Nieters INTERnet: nieters@crd.ge.com GE Corporate R&D BELLnet: (518) 387-5187 Schenectady, NY 12301
jik@athena.mit.edu (Jonathan I. Kamens) (02/20/91)
Question 7 on the comp.unix.questions FAQ posting is exactly the question you have asked, and an answer is provided. If the posting is not accessible at your site, E-mail me and I will send it to you. In the future, please check the FAQ posting before posting to comp.unix.wizards, or comp.unix.questions, or comp.unix.programmer, or whatever. That's what the FAQ exists for. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710
tchrist@convex.COM (Tom Christiansen) (02/20/91)
From the keyboard of nieters@crd.ge.com: : :hi : i have been RTFM'ing for long enough! time to post .... :-) Did you consider RTFFAQ? :the problem: : i want to write a program which will tell me if : a key has been pressed on the keyboard. i don't want to : intercept the key or modify it, i just want to catch the : "interrupt" and count it. ideally a blocking ioctl() or : equivalent would be best but i can sit in a busy loop and : poll until i see a key stroke, increment a counter, and continue. Unless you care whether they have hit a shift but no real character has actually been answered, this is way too much work. See the following FAQs (by question number) for further details: Group Q# comp.unix.questions 7 comp.lang.c 64 comp.lang.perl 16 --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "All things are possible, but not all expedient." (in life, UNIX, and perl)
rbj@uunet.UU.NET (Root Boy Jim) (02/26/91)
In article <NIETERS.91Feb19163332@eagle.crd.ge.com> nieters@crd.ge.com writes: >i've played with ioctl()'s to turn on LED's, keyclick, bell, find type >of keyboard, etc. etc. etc. but i'm getting very confused with this >key-press thing! I RTFM once or twice, too. It seems like this sort of thing should be easier to grok. The only program I know of that plays with the keyboard that you are likely to see source to is the X server. The is also a utility program that sets the keyboard mode. I believe there are four, ascii, and three other event encodings. -- [rbj@uunet 1] stty sane unknown mode: sane