home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
d
/
diskeys.zip
/
DISKEYS.C
next >
Wrap
C/C++ Source or Header
|
1992-01-23
|
4KB
|
126 lines
/*
Displays key codes when they are pressed.
Displays key combinations such as <CTL F1>, etc.
Uses BIOS call for Enhanced or Standard style keyboard.
ESC key ends the program.
----------------------------------------------------------------
*/
#include <conio.h>
#include <string.h>
#include <bios.h>
#include <stdio.h>
#include <stdlib.h>
unsigned returnval;
char decval[2];
unsigned hibyte;
unsigned lobyte;
char flag;
char lockstat[40];
char blanks[40];
union REGS in,out;
/*--------------------------------------------------------------------*/
main()
{
in.h.ah=0;
in.h.al=3;
int86(0x10,&in,&out); /*Set video mode 80x25 color*/
in.h.ah=5;
in.h.al=0;
int86(0x10,&in,&out); /*Set active video page*/
in.h.ah=6;
in.h.al=0;
in.h.bh=0x08;
in.h.ch=0;
in.h.cl=0;
in.h.dh=24;
in.h.dl=79;
int86(0x10,&in,&out); /*Blank entire screen*/
in.h.ah=2;
in.h.dh=1;
in.h.dl=3;
in.h.bh=0;
int86(0x10,&in,&out); /*Set cursor to row-1,col-3 */
in.h.ah=9;
in.h.al=205; /*double horizontal bar */
in.h.bh=0;
in.h.bl=0x0c; /*Attrib: bright red */
in.x.cx=74;
int86(0x10,&in,&out); /*Display chars*/
in.h.ah=2;
in.h.dh=5;
in.h.dl=3;
in.h.bh=0;
int86(0x10,&in,&out); /*Set cursor to row-5,col-3 */
in.h.ah=9;
in.h.al=205; /*double horizontal bar */
in.h.bh=0;
in.h.bl=0x0c; /*Attrib: bright red */
in.x.cx=74;
int86(0x10,&in,&out); /*Display chars*/
in.h.ah=2;
in.h.dh=2;
in.h.dl=8;
in.h.bh=0;
int86(0x10,&in,&out); /*Set cursor to row-2,col-8 */
puts("Displays keyboard scan codes (C)1991, George Rogozin.");
puts(" Press a key or key combination - press <ESC> to quit.");
cputs(" Enhanced or Standard keyboard (E/s)? ");
flag=getche();
in.h.ah=2;
in.h.dh=7;
in.h.dl=3;
in.h.bh=0;
int86(0x10,&in,&out); /*Set cursor to row-7,col-3 */
if(flag!='s' && flag!='S')
flag='e'; /* Set keyboard default */
do
{
strcpy(lockstat,blanks); /* Clear lockstat area */
if(flag=='e')
returnval=_bios_keybrd(_NKEYBRD_READ); /* enhanced board */
else returnval=_bios_keybrd(_KEYBRD_READ); /* standard board */
hibyte=0xff00 & returnval; /* Isolate scan code */
hibyte=hibyte>>8;
lobyte=0x00ff & returnval; /* Isolate ASCII code */
ultoa(lobyte,decval,10); /* Convert to string */
if(flag=='e')
returnval=_bios_keybrd(_NKEYBRD_SHIFTSTATUS); /* enhanced board */
else returnval=_bios_keybrd(_KEYBRD_SHIFTSTATUS); /* standard board */
in.h.ah=6;
in.h.al=0;
in.h.bh=0x08;
in.h.ch=7;
in.h.cl=0;
in.h.dh=25;
in.h.dl=79;
int86(0x10,&in,&out); /*Scroll up to clear data area */
in.h.ah=2;
in.h.dh=7;
in.h.dl=3;
in.h.bh=0;
int86(0x10,&in,&out); /*Set cursor to row-7,col-3 */
printf("\n Shift status value in hex: %.4X ",returnval);
if(0x0010 & returnval) strcat(lockstat,"SCROLL LOCK ");
if(0x0020 & returnval) strcat(lockstat,"NUM LOCK ");
if(0x0040 & returnval) strcat(lockstat,"CAPS LOCK ");
puts(lockstat);
printf(" Scan code value in hex: %.2X\n",hibyte);
printf(" ASCII key value in hex: %.2X\n",lobyte);
printf(" ASCII key value in dec: %s\n",decval);
printf(" ASCII printable char: %c\n",lobyte);
}
while (lobyte!=0x1B); /* Test for <ESC> */
in.h.ah=2;
in.h.dh=14;
in.h.dl=0;
in.h.bh=0;
int86(0x10,&in,&out); /*Set cursor at row 14 */
}