HPlogo HP Xlib Extensions: > Chapter 6 HP Input Device Extension Functions

Sample Use of HP Input Extensions

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

The following sample program, which creates a window and selects input from it, uses the HP Input device extension functions to access input devices other than the X pointer and keyboard.

NOTE: The functions used in this example are supported for compatibility with earlier versions of HP Xlib. Refer to the “Sample X Input Device Extension Program” for a sample program that uses the newer X standard input extension functions.
/************************************************************************
*
* File: hpinput.c
*
* Sample program to access input devices other than the X pointer and
* keyboard using the HP extension to X.
* This program creates a window and selects input from it.
* To terminate this program, press button 1 on any device being accessed
* through the extension.
*
* To compile this program, use
* "cc hpinput.c I/usr/include/X11R5 -L/usr/lib/X11R5
* -lXhp11 -lX11 -o hpinput
*/

#include <X11/Xlib.h>
#include <X11/XHPlib.h>
#include "stdio.h"

main()
{
Display *display;
XHPDeviceList *list, *slist;
int i, ndevices, devkeyp, devbutp;
Window my;
XEvent event;
Mask mask, tmask;
XHPDeviceButtonEvent *b;

if ((display = XOpenDisplay ("")) == NULL)
{
printf ("No connection to server - Terminating.\n");
exit(1);
}
my = XCreateSimpleWindow (display, RootWindow(display,0), 100, 100,
100, 100, 1, BlackPixel(display,0), WhitePixel(display,0));
XMapWindow (display, my);
XSync(display,0);
XHPGetExtEventMask (display, HPDeviceKeyPressreq, &devkeyp, &mask);
XHPGetExtEventMask (display,HPDeviceButtonPressreq,&devbutp,&tmask);
mask |= tmask;
slist = list = XHPListInputDevices (display, &ndevices);
for (i=0; i<ndevices; i++, list++)
{
printf ("\nDevice %s has %d keys and %d buttons\n",
list->name,list->num_keys,list->num_buttons);
if (list->x_id != XPOINTER &&list->x_id != XKEYBOARD)
{
XHPSetInputDevice (display, list->x_id, (ON | DEVICE_EVENTS));
XHPSelectExtensionEvent (display, my, list->x_id, mask);
}
}
for (;;)
{
XNextEvent (display,&event);
if (event.type == devkeyp)
printf ("Device key press event device=%d\n",
((XHPDeviceKeyEvent * ) &event)->deviceid);
else if (event.type == devbutp)
{
b = (XHPDeviceButtonEvent * ) &event;
printf ("Device button press event device=%d\n", b->deviceid);
if (b->ev.button==1)
{
for (i=0,list=slist; i<ndevices; i++,list++)
if (list->x_id != XPOINTER &&list->x_id != XKEYBOARD)
XHPSetInputDevice (display, list->x_id, OFF);
break;
}
}
}
XHPFreeDeviceList (slist);
}
© 1995 Hewlett-Packard Development Company, L.P.