-
...keyboard codes...
I am having trouble getting ALT and CONTROL as well as arrow keys.
I tried getch() but , as they say: "no workie"...
I found a function for getting keys:
Code:
int GetKey() {
union REGS regs;
regs.h.ah = 0x00;
int86(KEYBOARD, ®s, ®s);
return regs.x.ax;
}
Problem is my lib doesn't list a function "int86()" much less the union type "REGS"....
Any ideas?
-
Include...
#include<dos.h>
most of ur problems should be solved.
-
hmm, seems that I already did a search on the whole "includes" subfolder, but I will definately try again....
Thanks for the advice Vsriharsha...
-
Look at the c programming, this issue was frequently discussed there
-
Code:
#define KEYBDINT 0x09
#define CTRLBREAKINT 0x23
interrupt (*OldKeyHandler)(...)=0;
char keys[128];
//Installs KeyHandler on int 09h
void InstallKeyHandler(void);
//Removes/restores keyboard int 09h
void UninstallKeyHandler(void);
//Uninstalls all vectors for this process
void UninstallVectors(void);
//Installs all vectors for this process
void InstallVectors(void);
interrupt MyKeyboardHandler(...)
{
int key=inp(0x60);
if (key>128) //0x80
{
keys[key-128]=0;
} else keys[key]=1;
//Don't call the old handler
}
interrupt CtrlBreakHandler(...)
{
UninstallVectors(); //Restor vector table
exit(0); //exit
//no need to restore int 23h vector, DOS will do this
}
void InstallKeyHandler(void)
{
//DOS Way to install vector
OldKeyHandler=getvect(KEYBDINT);
setvect(KEYBDINT,MyKeyboardHandler);
}
void UninstallKeyHandler(void)
{
setvect(KEYBDINT,OldKeyHandler);
}
void InstallBreakHandler(void)
{
setvect(CTRLBREAKINT,BreakHandler);
}
void UninstallVectors(void)
{
UninstallKeyHandler();
//Any other vectors that need to be restored go here
}
void InstallVectors(void)
{
InstallBreakHandler();
InstallKeyHandler();
//any other handlers needing to be installed go here
}
Note that you do not have to explicitly restore the CTRL BREAK handler or the handler for INT 23h. DOS will do this for you. The main reason for the functions that install and uninstall the vectors is so that you can install all vectors and uninstall all vectors with one call. This is very handy for debugging because when you press CTRL BREAK, the vector table will be restored to its original state and you will be able to continue. You should also put in an atexit() function so that when exit(returncode) is issued, it will call atexit() which will call UninstallVectors. This will ensure that you will be able to write interrupt handlers, test them, and the system will remain stable.
To use this code:
if keys[scancode]
{
..key is pressed
} else ..key is not pressed
-
this would be probably not required since Bubba has already posted but i have used the bioskey() in bios.h for getting codes of keys
int key;
cout<<"PRESS A KEY..";
key=bioskey(0); //you press enter
cout<<key; //7181 is the output
-
unless bubba had already addressed it...
a practical way to handle input is to have seperate routines for the scan/ascii codes of 'regular' input, and one for the shift statii... [shifts alts caps scroll whatchamacallits and whatnot]... both would require a 16-bit value [short, compiler / target dependant...] put the shift status in a short, and the scan and ascii codes in one short... and you have it...
also, while i'm at it... checking for keystrokes and returning them only if availiable can help so you don't have to wait for input [like you would if using getch...]
does anyone know the interrupts offhand for shift status'? currently mine is just a wrapper over _bios_keybrd (_NKEYBRD_SHIFTSTATUS) ... thanks... [will check RBIL... eventually Bubba... :)]
-
The shift status of keys can be trapped by checking certain bits in the return code. Each bit represents whether or not left shift, right shift, CTRL, ALT, NumLock, etc., are down or not.
I believe that the bit pattern is identical to that of the BIOS keyboard interrupt.
-
oh sorry if i wasn't clear, when mentioning 'shift status'' i was refering to the entire control word... as i said my current usage is just a wrapper over a library function... which is the interrupt? thanks.