Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!aplcomm!uunet!munnari.oz.au!goanna!giaea!s9100202 From: s9100202@giaea.gi.oz (Lee Hollingworth) Newsgroups: comp.os.msdos.programmer Subject: Re: Reading extended keys Message-ID: <1988@giaea.gi.oz> Date: 19 Jun 91 12:04:13 GMT References: Organization: Monash University College Gippsland, Churchill 3842, Victoria, AUSTRALIA. Lines: 102 In article userRPCP@mts.ucs.UAlberta.CA (Junior Physicist) writes: >I wonder if anyone out there can help me. I'm using Borland >Turbo C++ v1.01 and I need to be able to detect when an >extended key is pressed ie. F1-F10, Shift F1-F10, etc. > >Can anyone out there tell me how to do this? It's easy enough >in Borland's Turbo Pascal. Thanks a bunch in advance. > >Replies can be e-mailed to me. I tried but they bounced... I don't use TC++ or BC++, so I'm not sure if these compilers come with the functions getch() & getche(). Which are functions which allow you to get a single character without, or with echo, without having to press the return or enter key. (Function getchar() requires the user to press enter after the entered key). These functions are available with Microsoft C, prototyped in . I have included an assembly listing, as they are extremely easy to write, just incase your compiler(s) do not have the functions available. Of course you need to assemble the files and then link them with your C source. To test a function key, or indeed any extended key code, you need to make one call to see if the value returned by getch() or getche() is 0, if it is then an extended scan code has been entered, and you must call the function again to see what the actual scan code is. A sample C listing is shown below, making use of the assembly code listing which follows. (Start of C source code) /* ------------------------------------------------------------------------- */ #include extern int getch(void); /* in file getc.asm (assembly code) */ extern int getche(void); /* in file getc.asm (assembly code) */ void main() { int key; printf("Press any key: "); key = getch(); if(key == 0){ key = getch(); printf("\nExtended key scan code is %d\n", key); } else printf("\nYou pressed the %c key\n", key); } /* -----------------------------------------------------------------------*/ (End of C source code) (Start of assembly code) ;--------------------------------------------------------------------------- ;---------------------------------------------------------------------------; ; getc.asm ; ; Note: All functions are written to make use of the Microsoft C calling ; ; convention which does not require scratch pad registers to be ; ; saved or restored. ; ;---------------------------------------------------------------------------; .MODEL small .CODE PUBLIC _getch ;---------------------------------------------------------------------------; ; This function gets a single character input without echo ; ; returns in ax ; ;---------------------------------------------------------------------------; _getch PROC mov ah,8 int 21h xor ah,ah ret _getch ENDP PUBLIC _getche ;---------------------------------------------------------------------------; ; This function gets a single character input with echo ; ; returns in ax ; ;---------------------------------------------------------------------------; _getche PROC mov ah,1 int 21h xor ah,ah ret _getche ENDP END ;----------------------------------------------------------------------------- (end of source code) Hope that is of help to you. Lee Hollingworth s9100202@giae.oz.au