Thanks bithub, I've passed the link on to my brother.
I'm still interested in creating a simple bespoke version for him, and have thrown together some basic functions. Please note that this is currently untested mailer code right off the top of my head, so may not compile cleanly.
Code:
#include <stdio.h>
#include <dos.h>
typedef union _Keypress
{
int iKeyCode;
char ch[2];
} KEY;
#define KEYBOARD 0x16
#define KEYCODE iKeyCode
#define SCANCODE ch[1]
#define ASCIICODE ch[0]
#define NO_KEY 0
#define ESCAPE_KEY 1
int insert_keypress(KEY k)
{
union REGS sreg,dreg;
sreg.h.ah = 5; /* Set 'Store' Function */
sreg.h.ch = k.SCANCODE; /* Set Key Scancode */
sreg.h.cl = k.ASCIICODE; /* Set Key ASCII Code */
int86(KEYBOARD, &sreg, &dreg);
return ( dreg.h.al ); /* Success (1) or Fail (0) */
}
int get_keypress(void)
{
KEY symKey;
union REGS sreg,dreg;
sreg.h.ah = 0; /* Set 'Get' Function */
int86(KEYBOARD, &sreg, &dreg);
k.SCANCODE = dreg.h.ah; /* Get Key Scancode */
k.ASCIICODE = dreg.h.al; /* Get Key ASCII Code */
return k.KEYCODE;
}
int check_keypress(void)
{
KEY k;
union REGS sreg,dreg;
sreg.h.ah = 0; /* Set 'Check' Function */
int86(KEYBOARD, &sreg, &dreg);
/* Check the zflag (0=nothing in queue, 1=key pressed) */
if ( regs.x.cflags & 0x0040 ) {
k.KEYCODE = 0; /* Nothing in queue */
} else {
k.SCANCODE = dreg.h.ah; /* Get Key Scancode */
k.ASCIICODE = dreg.h.al; /* Get Key ASCII Code */
}
return k.KEYCODE;
}
void flush_kb_buffer(void)
{
KEY symKey;
while (check_keypress()) {
symKey.KEYCODE = get_keypress();
}
}
void main(void)
{
KEY k, temp, ;
flush_kb_buffer();
printf("Enter key to repeat:");
k.KEYCODE = get_keypress();
while (k.SCANCODE != ESCAPE_KEY) {
if ((temp = check_keypress()) == 0) {
/* Nothing in buffer queue, put something in */
printf("Inserting Keypress\r\n");
insert_keypress(k);
} else {
/* We have something in the buffer, grab it */
k.KEYCODE = get_keypress();
}
}
printf("Goodbye!\r\n");
}
You will also notice that I'm using the INT16h DOS interrupt, and function 05h to insert the keypress. Apparently this worked on some, but not all old PC's, and probably won't work on modern ones. Does anyone know another approach I can use.
The get_keypress and check_keypress functions I wrote above should work exactly like the old obsolete bioskey(0) and bioskey(1) functions if you wanted to look them up. These should be compatible with modern Windows-based PC's.