getkey.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* $Id$
  2. * MegaZeux
  3. *
  4. * Copyright (C) 1996 Greg Janson
  5. * Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
  6. * Copyright (C) 1999 Charles Goetzman
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. // getkey function to input from the keyboard.
  23. #include "helpsys.h"
  24. #include <conio.h>
  25. #include "getkey.h"
  26. #include "mouse.h"
  27. #include <_null.h>
  28. #include "counter.h"
  29. mouse_info_rec mouse_event={ 0,0,0 };
  30. char auto_pop_mouse_events=1;
  31. char allow_help=1;
  32. //Local, for keywaiting function
  33. mouse_info_rec temp_mev={ 0,0,0 };
  34. char keywaiting(void) {
  35. if(kbhit()) return 1;//Key waiting
  36. mouse_check_loop:
  37. if(m_check()) {//Check for a REAL mouse event
  38. m_preview(&temp_mev);
  39. if(temp_mev.buttonstat&(LEFTBPRESS|RIGHTBPRESS)) return 1;
  40. acknowledge_mouse();
  41. }
  42. return 0;
  43. }
  44. int getkey(void) {
  45. int t1;
  46. do { } while((!kbhit())&&(!m_check()));
  47. if((m_check())&&(!kbhit())) {
  48. m_preview(&mouse_event);
  49. //Forget release events
  50. if(!(mouse_event.buttonstat&(LEFTBPRESS|RIGHTBPRESS))) {
  51. //No new button presses
  52. acknowledge_mouse();
  53. return 0;
  54. }
  55. //Turn right button into ESC (Not anymore! Spid)
  56. if(mouse_event.buttonstat&RIGHTBPRESS) {
  57. acknowledge_mouse();
  58. return 0; // WAS 27. Spid
  59. }
  60. if(auto_pop_mouse_events) acknowledge_mouse();
  61. return MOUSE_EVENT;
  62. }
  63. t1=getch();
  64. if(t1==0) {
  65. t1=-getch();
  66. //Help?
  67. if((allow_help)&&(t1==-59)&&(get_counter("HELP_MENU"))) {
  68. help_system();
  69. return 0;
  70. }
  71. }
  72. return t1;
  73. }
  74. void acknowledge_mouse(void) {
  75. m_get(NULL);
  76. }