Message-ID: <38DFBF98.8BEB44EB@corel.com> Date: Mon, 27 Mar 2000 15:07:52 -0500 From: Jonathan Meunier X-Mailer: Mozilla 4.7 [en] (Win95; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: keyboard interrupt References: <8bod7h$rj1$1 AT gxsn DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 120.150.3.42 X-Trace: 27 Mar 2000 15:07:01 -0500, 120.150.3.42 Lines: 86 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Here's the one I use.. This is by no means a tutorial, simply cuz it's not commented :) but if you need a good tutor, try PCGPE (PC Game Programming Encyclopedia).. http://www.qzx.com/pc-gpe/keyboard.txt ---[keyboard.cpp]--- #include "keyboard.h" // all #defines for keys (ie: #define ESC 1 extern bool quit_prog; bool kb_installed = FALSE; bool keyboard[256]; // all possible characters _go32_dpmi_seginfo old_kb_seginfo, new_kb_seginfo; void new_keyboard_int() { unsigned char keyscan; keyscan = inportb(0x60); keyboard[keyscan] = TRUE; if(keyscan > 0x80) keyboard[keyscan - 0x80] = TRUE; outportb(0x20,0x20); // acknowledge interrupt } void install_keyboard() { if(kb_installed == TRUE) return; new_kb_seginfo.pm_offset = (int)new_keyboard_int; new_kb_seginfo.pm_selector = _go32_my_cs(); kb_installed = TRUE; _go32_dpmi_get_protected_mode_interrupt_vector(0x09, &old_kb_seginfo); _go32_dpmi_allocate_iret_wrapper(&new_kb_seginfo); _go32_dpmi_set_protected_mode_interrupt_vector(0x09, &new_kb_seginfo); } void uninstall_keyboard() { if(kb_installed == FALSE) return; kb_installed = FALSE; _go32_dpmi_set_protected_mode_interrupt_vector(0x09, &old_kb_seginfo); _go32_dpmi_free_iret_wrapper(&new_kb_seginfo); } void check_keyboard() { if(keyboard[ESC] == TRUE) quit_prog = TRUE; } ---[eof]--- ---[test.cpp]--- bool quit_prog = FALSE; void main() { install_keyboard(); do { // do stuff check_keyboard(); } while(quit_prog != TRUE); uninstall_keyboard(); } ---[eof]--- HTH, .(Trancelucid). . Jaune . Anthony Graham wrote: > > I've been experimenting with the __dmpi and _go32 things and would like to > know if anyone would be able to tell me how to do a simple keyboard routine > (no assembly) that increases a variable whenever a key is pressed, (I'll > make the thing a little more useful later, I just need to know how to > replace the default keyboard interrupt routine without it crashing), also > putting it back to normal after Q is pressed would be really helpful too. > > thanks loads. > > -Anthony