Nachricht #34 aus Archiv der Liste gnuports@2rosenthals.com

Von: "Dave Yeo" <gnuports@2rosenthals.com> Kopfzeilen anzeigen
E-Mail Quelltext
Betreff: Re: [GNU Ports] getting a single keypress
Datum: Mon, 16 May 2022 12:10:54 -0700
An: GNU Ports for eCS Mailing List <gnuports@2rosenthals.com>

On 05/16/22 12:09 AM, Steven Levine wrote:
In <list-3691732@2rosenthals.com>, on 05/15/22
   at 09:07 PM, "Dave Yeo" <gnuports@2rosenthals.com> said:

Hi Dave,

Ideas or fixes?
The OS/2 APIs you want are KbdPeek and KbdCharin.  I suspect if you search
the kLIBC sources you will find the kLIBC  APIs that wrap test low level
routines.

OK, went with the libc version of kbdCharin(), which seems more 32 bit friendly. Only problem is at the test program start, it displays an "Î".
Test program,

#define INCL_KBD
#define INCL_DOSPROCESS
#include <os2.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/select.h>
#include <unistd.h>
#include <termios.h>

int term_fd = -1;

int get_key(int do_delay, char *val)
{
        KBDKEYINFO key;
        key.chChar = 0;
        key.chScan = 0;
        // optionally: sleep for a tiny bit, actually needed to stop blocking the WPS
        DosSleep(5);
        if(!KbdCharIn(&key,IO_NOWAIT,0) && key.chChar)
        {
                *val = key.chChar;
                return 1;
        }
        return 0;
}


int main(int argc, char **argv)
{
        if(argc >= 2)
                term_fd = open("CON:", O_RDONLY);
        else
                term_fd = STDIN_FILENO;
        if(term_fd < 0)
        {
                perror("failure opening terminal input");
                return 1;
        }
        fprintf(stderr, "terminal fd: %d\n", term_fd);

        struct termios old_tio;
        int termsetup = 0;
        if(!tcgetattr(term_fd, &old_tio))
        {
                fprintf(stderr, "proper terminal setup\n");
                struct termios tio = old_tio;
                tio.c_lflag &= ~(ICANON|ECHO);
                tio.c_cc[VMIN] = 1;
                tio.c_cc[VTIME] = 0;
                tcsetattr(term_fd,TCSANOW,&tio);
                termsetup = 1;
        }

        char val = 0;
        while(val != 'q')
        {
                if(get_key(1, &val))
                        fprintf(stderr, "got key: %c\n", val);
        }

        if(termsetup)
                tcsetattr(term_fd,TCSAFLUSH,&old_tio);
        if(term_fd > 0)
                close(term_fd);
        return 0;
}


Dave


Abonnieren: Nachricht (Feed), Sammelnachricht (Digest), Index.
Abmelden
E-Mail an ListMaster