Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to detect status of keyboard (solaris)

Posted on 1997-11-13
5
Medium Priority
?
453 Views
Last Modified: 2013-12-05
Hi, Everyone who can help me,

I need to detect the  status of keyboard. In fact, what I want to know is: how to record the time duration of pressing a key. Getche or getch will accept keyboard input, but as soon as a key is pressed, the function will return a value. I need to realize some functions like DOS keyboard interrupt which can tell me when a key is pressed, when it is released, etc. My working platform is SUN workstation, Solaris 2.5.1

Thanks,

--
Yan, Bo

ECECS Dept. University of CincinnatiC
0
Comment
Question by:byan
  • 2
  • 2
5 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 1256316
man XQueryKeymap
0
 

Author Comment

by:byan
ID: 1256317
Edited text of question
0
 
LVL 85

Expert Comment

by:ozo
ID: 1256318
Is your keyboard /dev/kbd?  Try ioctl(kb,KIOCTRANS,TR_NONE )
0
 

Author Comment

by:byan
ID: 1256319
B
0
 
LVL 1

Accepted Solution

by:
dhughes111797 earned 800 total points
ID: 1256320
PGP gets the interval between key presses (for setting up
randomness). You may want to look at this code.  Also, if
you are programming in X11 you can use events to notify you
when a key has been pressed and released. see XEvent, XAnyEvent
man pages. Also, 2.5.1 comes with Motif in /usr/dt so you can
use the Motif functions to make it easier.

Here's a simple codeblock:

#include <time.h>
#include <X11/Xlib.h>
 
 
void main()
{
    Display *d;
    Window w;
    XEvent e;
    double frac;
    struct timespec time1, time2;
 
    d = XOpenDisplay(NULL);
    w = XCreateSimpleWindow(d, XDefaultRootWindow(d), 10, 10, 100, 100, 2, 0,
0);
    XMapWindow(d, w);
    XSelectInput(d, w, KeyPressMask | KeyReleaseMask);
 
    while (True)
    {
        XNextEvent(d, &e);
 
   
        if (e.type == KeyPress)
            clock_gettime(CLOCK_REALTIME, &time1);
        else if (e.type == KeyRelease) {
            clock_gettime(CLOCK_REALTIME, &time2);
            frac = ((double) time2.tv_nsec - time1.tv_nsec) / 1000000000;
            if (frac < 0) {
                frac++;
                time2.tv_sec--;
            }
            printf("duration %2.2f seconds\n", (double) time2.tv_sec -
                time1.tv_sec + frac);
        }
    }
}

Also, see man -s7 kb, man -s7m kb

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question