Home
Developer Resources
QNX RTOS v4
QNX RTOS v4 Knowledge Base

QNX RTOS v4 Knowledge Base

Foundry27
Foundry27
QNX RTOS v4 project
Resources

QNX RTOS v4 Knowledge Base

Title Testing the Scroll lock state
Ref. No. QNX.000009236
Category(ies) Input Devices, Development, Character I/O
Issue How can we test the Numlock, Scroll lock, and/or Caps lock?

We found them defined in sys/qioctl.h but we are still not sure how to test if the state is "on" or "off".







Solution Here's some code that should help(NOTE: The /dev/kbd can be changed to /dev/usbkbd0 to read from a usb keyboard.):

keystate.c

#ifdef __USAGE
keystate
#endif

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <ctype.h>
#include <termios.h>
#include <sys/dev.h>
#include <sys/qioctl.h>
#include <sys/kernel.h>
#include <term.h>

main(argc, argv)
int argc;
char *argv[];
        {
        int fd;
        long lval[2];
        struct termios tios;

        if(tcgetattr(0, &tios) == -1) {
                fprintf(stderr, "%s: Not a terminal devicen", argv[0]);
                exit(EXIT_FAILURE);
                }
        fd = open("/dev/kbd", O_RDONLY);
        /*
        * Get state of keyboard numlock etc..
        */
        lval[0] = 0;
        lval[1] = 0;
        if(qnx_ioctl( fd, QCTL_DEV_CTL, &lval[0], 8, &lval[0], 4 ) == 0 ) {
                printf("%cnumlock",  (lval[0] & 0x000002L) ? '+' : '-');
                printf(" %ccapslock",(lval[0] & 0x000004L) ? '+' : '-');
                printf(" %cscrlock", (lval[0] & 0x004001L) ? '+' : '-');
        printf("n");
        }
        close(fd);
    }

As well, you can query the state of the serial lines(in case anyone else is looking for this)

serline.c

#ifdef __USAGE

e.g. serline </dev/ser1

#endif

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <ctype.h>
#include <termios.h>
#include <sys/dev.h>
#include <sys/qioctl.h>
#include <sys/kernel.h>
#include <term.h>

main(argc, argv)
int argc;
char *argv[];

        {
        long lval[2];
        struct termios tios;

        if(tcgetattr(0, &tios) == -1) {
                fprintf(stderr, "%s: Not a terminal devicen", argv[0]);
                exit(EXIT_FAILURE);
                }

        /*
        * Get state of hardware lines
        */
        lval[0] = 0;
        lval[1] = 0;
        if(qnx_ioctl( 0, QCTL_DEV_CTL, &lval[0], 8, &lval[0], 4 ) == 0 ) {
                printf("%cDTR",  (lval[0] & 0x000001L) ? '+' : '-');
                printf(" %cRTS", (lval[0] & 0x000002L) ? '+' : '-');
                printf(" %cBRK", (lval[0] & 0x004000L) ? '+' : '-');
                printf(" %ccts", (lval[0] & 0x100000L) ? '+' : '-');
                printf(" %cdsr", (lval[0] & 0x200000L) ? '+' : '-');
                printf(" %cri",  (lval[0] & 0x400000L) ? '+' : '-');
                printf(" %ccd",  (lval[0] & 0x800000L) ? '+' : '-');
        printf("n");
        }
    }