Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for keylocks.pl

(view source code of keylocks.pl as plain text)

  1. #! perl
  2.  
  3. # Check command line arguments (none required)
  4. if ( $ARGV[1] ) {
  5. 	Syntax();
  6. }
  7.  
  8. # Create temporary DEBUG script
  9. $dbg = "D 0:417\nQ\n";
  10. open( DBGSCR, "> keylocks.dbg" ) || die( "Cannot open temporary DEBUG script: $!" );
  11. print DBGSCR $dbg;
  12. close DBGSCR;
  13.  
  14. # Run DEBUG script and filter output;
  15. `debug.exe < keylocks.dbg` =~ /\s{10}(\d\d)\-\d\d/;
  16. #eval "\$keylocks = 0x".$1;
  17. $keylocks = ( hex "0x".$1 ) & 0x70;
  18.  
  19. $capslock   = ( $keylocks & 0x40 ) / 0x40;
  20. $numlock    = ( $keylocks & 0x20 ) / 0x20;
  21. $scrolllock = ( $keylocks & 0x10 ) / 0x10;
  22.  
  23. $msg_caps   = ( ( uc $ARGV[0] ne "N" and uc $ARGV[0] ne "S" ) ? "CapsLock=$capslock\n"     : "" );
  24. $msg_num    = ( ( uc $ARGV[0] ne "C" and uc $ARGV[0] ne "S" ) ? "NumLock=$numlock\n"       : "" );
  25. $msg_scroll = ( ( uc $ARGV[0] ne "C" and uc $ARGV[0] ne "N" ) ? "ScrollLock=$scrolllock\n" : "" );
  26. print $msg_caps.$msg_num.$msg_scroll;
  27.  
  28. if ( $ARGV[0] ) {
  29. 	$keylocks = ( ( uc $ARGV[0] ne "N" and uc $ARGV[0] ne "S" ) ? $capslock   : $keylocks );
  30. 	$keylocks = ( ( uc $ARGV[0] ne "C" and uc $ARGV[0] ne "S" ) ? $numlock    : $keylocks );
  31. 	$keylocks = ( ( uc $ARGV[0] ne "C" and uc $ARGV[0] ne "N" ) ? $scrolllock : $keylocks );
  32. }
  33.  
  34. # Delete temporary DEBUG script
  35. `DEL keylocks.dbg >NUL 2>&1`;
  36.  
  37. # Return code is the key locks status
  38. exit $keylocks;
  39.  
  40.  
  41. sub Syntax {
  42. 	print "\nKeyLocks.pl,  Version 1.00 for DOS, Windows & OS/2\n",
  43. 	      "Returns the status of the CapsLock, NumLock and ScrollLock keys\n\n",
  44. 	      "Usage:  KEYLOCKS.PL  [ C | N | S ]\n\n",
  45. 	      "Where:  C is for CapsLock status, N for NumLock, and S for ScrollLock.\n",
  46. 	      "        By default the status for all three is displayed.\n\n",
  47. 	      "Notes:  Depending on the optional command line argument, either the status of\n",
  48. 	      "        the requested key lock or that of all key locks is displayed on screen,\n",
  49. 	      "        and the return code will either be the status of the requested key lock\n",
  50. 	      "        (0=OFF, 1=ON) or a combination of the three (OFF=0, CapsLock ON=64,\n",
  51. 	      "        NumLock ON=32, and ScrollLock ON=16, all added together).\n",
  52. 	      "        This script uses the DEBUG command to read the keyboard status.\n\n",
  53. 	      "Written by Rob van der Woude\n",
  54. 	      "http://www.robvanderwoude.com\n";
  55. 	exit;
  56. }
  57.  

page last uploaded: 2017-08-21, 14:26