1 /** 2 ** w32keys.c ---- DOS (TCC/BCC/DJGPP: "conio.h") style keyboard utilities 3 ** 4 ** Author: Gernot Graeff 5 ** E-mail: gernot.graeff@t-online.de 6 ** Date: 02-11-99 7 ** 8 ** This file is part of the GRX graphics library. 9 ** 10 ** The GRX graphics library is free software; you can redistribute it 11 ** and/or modify it under some conditions; see the "copying.grx" file 12 ** for details. 13 ** 14 ** This library is distributed in the hope that it will be useful, 15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 ** 18 **/ 19 20 #include "libwin32.h" 21 #include "libgrx.h" 22 #include "input.h" 23 #include "grxkeys.h" 24 GrKeyPressed(void)25int GrKeyPressed(void) 26 { 27 if (MOUINFO->msstatus < 2) { 28 GrMouseInit(); 29 GrMouseEventEnable(1, 0); 30 } 31 return _GrKeyPressed(); 32 } 33 GrKeyRead(void)34GrKeyType GrKeyRead(void) 35 { 36 GrMouseEvent ev; 37 int i, key; 38 39 if (!_GrIsKbdEnabled()) { 40 while (_nkeysw32pool < 1) 41 _GrUpdateInputs(); 42 key = _keysw32pool[0]; 43 for (i = 0; i < _nkeysw32pool; i++) 44 _keysw32pool[i] = _keysw32pool[i + 1]; 45 _nkeysw32pool--; 46 return key; 47 } 48 49 if (MOUINFO->msstatus < 2) { 50 GrMouseInit(); 51 GrMouseEventEnable(1, 0); 52 } 53 for (;;) { 54 GrMouseGetEvent((GR_M_EVENT | GR_M_NOPAINT), &ev); 55 if (ev.flags & GR_M_KEYPRESS) { 56 return (ev.key); 57 } 58 } 59 } 60 GrKeyStat(void)61int GrKeyStat(void) 62 { 63 return _GrKeyStat(); 64 } 65 kbhit(void)66int kbhit(void) 67 { 68 return GrKeyPressed(); 69 } 70 getkey(void)71int getkey(void) 72 { 73 return (int)GrKeyRead(); 74 } 75 getch(void)76int getch(void) 77 { 78 static int lastkey = (-1); 79 int key; 80 81 if (lastkey != (-1)) { 82 key = lastkey; 83 lastkey = (-1); 84 return (key); 85 } 86 key = getkey(); 87 if (key < 0x100) { 88 return (key); 89 } 90 lastkey = key & 0xff; 91 92 return (0); 93 } 94 getkbstat(void)95int getkbstat(void) 96 { 97 return _GrKeyStat(); 98 } 99 100