I'm very close.
So close that it is working fine for
both 16-bit and 32-bit in a fullscreen
window.
However in a normal window, in both
cases, it works until the DosRead (when
I want things to be back to normal), and
hangs. The keyboard no longer works.
I suspect I have a new issue.
Like I need to create a logical keyboard
or something like that before I do the
DevIoCtl. But that theory doesn't explain
why it is necessary, given that I put
things back to normal already.
cl /Lp mstest.c /link /pm:vio
#include <stdio.h>
#define INCL_DOS
#define INCL_DOSDEVICES
#define INCL_KBD
#include <os2.h>
int main(void)
{
USHORT rc;
ULONG tempRead;
USHORT parm = 1;
ULONG parmlen = sizeof parm;
KBDKEYINFO cd;
ULONG datalen = 0;
unsigned char data[200];
unsigned char parmdata[200];
/* WORD */ SHORT parmword = 1;
BYTE bb = 0x80;
static KBDINFO kinfo;
static STRINGINBUF si;
HKBD hk = 0;
USHORT len = 0;
static USHORT newkeyb[2];
USHORT action;
USHORT fileAttr = 0;
USHORT openAction = 0;
USHORT openMode = 0;
ULONG newsize = 0;
#if 1
printf("about to DosOpen\n");
openMode = OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE;
openAction |= OPEN_ACTION_OPEN_IF_EXISTS;
/* tried KBD$ and CON */
/* replacement - not really equivalent of KbdOpen */
rc = DosOpen((PSZ)"KBD$",
&hk,
&action,
newsize,
fileAttr,
openAction,
openMode,
0);
printf("rc is %d, hk is %x\n", rc, (int)hk);
#endif
#if 0
printf("about to get input mode\n");
/* equivalent of KbdSetStatus - just for
ASCII/binary - echo not relevant */
rc = DosDevIOCtl(&bb,
NULL, /* &cd, */
0x71, /* function */
4, /* category - 4 = keyboard - not supported in FAPI */
hk); /* handle */
printf("rc is %d, bb is %x\n", rc, bb);
#endif
#if 1
printf("about to set binary mode\n");
/* set binary mode */
bb = 0x80;
/* equivalent of KbdSetStatus - only setting
binary - echo not really relevant */
rc = DosDevIOCtl(NULL,
&bb,
0x51, /* function */
4, /* category - 4 = keyboard - not supported in FAPI */
hk); /* handle */
printf("rc is %d\n", rc);
#endif
#if 1
printf("about to read via 4/74\n");
/* read character records */
rc = DosDevIOCtl(&cd,
&parmword,
0x74, /* function */
4, /* category - 4 = keyboard - not supported in FAPI */
hk); /* handle */
printf("rc is %d\n", rc);
printf("chchar is %x, chscan is %x\n", cd.chChar, cd.chScan);
#endif
#if 1
printf("about to set back to ASCII\n");
/* note that failure to set back to ASCII
causes subsequent DosRead to remain in
binary mode, even after this handle is closed */
bb = 0;
/* equivalent of KbdSetStatus - only setting
ASCII - echo not changed/relevant */
rc = DosDevIOCtl(NULL,
&bb,
0x51, /* function */
4, /* category - 4 = keyboard - not supported in FAPI */
hk); /* handle */
printf("rc is %d\n", rc);
#endif
#if 1
printf("about to DosClose\n");
rc = DosClose(hk);
printf("rc is %d\n", rc);
#endif
printf("about to DosRead\n");
rc = DosRead(0 /* hk */, data, 7, &len);
printf("rc %d, len %d, bytes %x %x %x\n", rc, len, data[0], data[1],
data[2]);
return 0;
}
wcl386 -bcl=os2v2 newtest.c
#include <stdio.h>
#define INCL_DOS
#define INCL_DOSDEVICES
#define INCL_KBD
#include <os2.h>
int main(void)
{
USHORT rc;
ULONG tempRead;
USHORT parm = 1;
KBDKEYINFO cd;
ULONG datalen = 0;
unsigned char data[200];
unsigned char parmdata[200];
/* WORD */ SHORT parmword = 1;
BYTE bb = 0x80;
static KBDINFO kinfo;
static STRINGINBUF si;
HFILE hk = 0;
USHORT len = 0;
static USHORT newkeyb[2];
ULONG action;
ULONG fileAttr = 0;
ULONG openAction = 0;
ULONG openMode = 0;
ULONG newsize = 0;
ULONG datamax;
ULONG parmmax;
ULONG parmlen;
#if 1
printf("about to DosOpen\n");
openMode = OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE;
openAction |= OPEN_ACTION_OPEN_IF_EXISTS;
/* tried KBD$ and CON */
/* replacement - not really equivalent of KbdOpen */
rc = DosOpen((PSZ)"KBD$",
&hk,
&action,
newsize,
fileAttr,
openAction,
openMode,
0);
printf("rc is %d, hk is %x\n", rc, (int)hk);
#endif
#if 1
printf("about to set binary mode\n");
/* set binary mode */
bb = 0x80;
/* equivalent of KbdSetStatus - only setting
binary - echo not really relevant */
rc = DosDevIOCtl(hk,
4, /* category - 4 = keyboard - not supported in FAPI */
0x51, /* function */
&bb,
1,
&parmlen,
NULL,
0,
&datalen
); /* handle */
printf("rc is %d\n", rc);
#endif
#if 1
printf("about to read via 4/74\n");
/* read character records */
parmmax = sizeof parmword;
parmlen = 0;
rc = DosDevIOCtl(hk,
4, /* category - 4 = keyboard - not supported in FAPI */
0x74, /* function */
&parmword,
parmmax,
&parmlen,
&cd,
sizeof cd,
&datalen
); /* handle */
printf("rc is %d\n", rc);
printf("chchar is %x, chscan is %x\n", cd.chChar, cd.chScan);
#endif
#if 1
printf("about to set back to ASCII\n");
/* note that failure to set back to ASCII
causes subsequent DosRead to remain in
binary mode, even after this handle is closed */
bb = 0;
datalen = 0;
/* equivalent of KbdSetStatus - only setting
ASCII - echo not changed/relevant */
rc = DosDevIOCtl(hk,
4, /* category - 4 = keyboard - not supported in FAPI */
0x51, /* function */
&bb,
1,
&parmlen,
NULL,
0,
&datalen
); /* handle */
printf("rc is %d\n", rc);
#endif
#if 1
printf("about to DosClose\n");
rc = DosClose(hk);
printf("rc is %d\n", rc);
#endif
/* in a fullscreen window, this works fine.
in a normal window, dosread hangs */
printf("about to DosRead\n");
rc = DosRead(0 /* hk */, data, 7, &tempRead);
printf("rc %d, len %d, bytes %x %x %x\n", rc, tempRead, data[0],
data[1], data[2]);
return 0;
}
Any ideas?
Thanks. Paul.