home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / imc9102.zip / SHIFTLOK.C < prev    next >
C/C++ Source or Header  |  1991-01-15  |  2KB  |  79 lines

  1. /********************************************************
  2. *    SHIFTLOK.C - manipulate the BIOS keyboard status    *
  3. *    To compile: cl shiftlok                                *
  4. ********************************************************/
  5.  
  6. #include <stdio.h>
  7. #include <dos.h>
  8.  
  9. /* Key definitions in the BIOS data region */
  10. #define RIGHT_SHIFT        0x0001
  11. #define LEFT_SHIFT        0x0002
  12. #define CTRL_KEY        0x0004
  13. #define ALT_KEY            0x0008
  14. #define SCROLLLOK_MODE    0x0010
  15. #define NUMLOK_MODE        0x0020
  16. #define CAPSLOK_MODE    0x0040
  17. #define INSERT_MODE        0x0080
  18. #define LEFT_CTRL        0x0100
  19. #define LEFT_ALT        0x0200
  20. #define SYS_REQ            0x0400
  21. #define PAUSE_MODE        0x0800
  22. #define    SCROLLLOK_KEY    0x1000
  23. #define NUMLOK_KEY        0x2000
  24. #define CAPSLOK_KEY        0x4000
  25. #define INSERT_KEY        0x8000
  26.  
  27. /* Settings for setKbdStatus */
  28. #define    OFF                10
  29. #define ON                11
  30. #define TOGGLE            12
  31.  
  32. /****************************************************************
  33. *    setKbdStatus - set the status of a key or mode                *
  34. *    INP:    key - key or mode to alter                            *
  35. *            setting - OFF, ON, or TOGGLE                        *
  36. ****************************************************************/
  37. void setKbdStatus(unsigned key, int setting)
  38.     {
  39.     unsigned int far *p;
  40.  
  41.     FP_SEG(p) = 0x0040;
  42.     FP_OFF(p) = 0x0017;
  43.     if (setting==TOGGLE)    *p ^= key;
  44.     else if (setting==ON)    *p |= key;
  45.     else if (setting==OFF)    *p &= !key;
  46.     }
  47.  
  48. /****************************************************************
  49. *    getKbdStatus - return the status of a key or mode            *
  50. *    INP:    key - the key or mode to retrieve the status of        *
  51. *    OUT:    0 if mode or key is OFF, 1=ON                        *
  52. ****************************************************************/
  53. int getKbdStatus(unsigned key)
  54.     {
  55.     unsigned int far *p;
  56.  
  57.     FP_SEG(p) = 0x0040;
  58.     FP_OFF(p) = 0x0017;
  59.     return *p & key;
  60.     }
  61.  
  62. /****************************************************************
  63. *    main() - demonstration program to show how to use the        *
  64. *    getKbdStatus() and setKbdStatus() functions.                *
  65. ****************************************************************/
  66. void main(void)
  67.     {
  68.     char buff[100];
  69.  
  70.     printf("Current right shift key status is: %s\n",
  71.         getKbdStatus(RIGHT_SHIFT) ? "on" : "off");
  72.     puts("Get a string with the current right shift key status");
  73.     gets(buff);
  74.     
  75.     setKbdStatus(RIGHT_SHIFT,TOGGLE);
  76.     puts("Get a string with the opposite right shift status");
  77.     gets(buff);
  78.     }
  79.