Name    :Keysense.com                                                           
Usage   :Passes Keypress' and shift state to batch files.                       
        :Keysense with no parameters defaults to Keypress which reads any key   
        :pressed including extended keys. Must be called again for second part  
        :of errorlevel number remaining in keybuffer if extended keypressed.    
        :The errorlevel value is equal to the ASCII value of the key pressed.   
        :Consult your manuals for ASCII values of keypresses.                   
                                                                                
        :If An Invalid Parameter Is Passed, Keysense Defaults To None (A).      
                                                                                
        :Parameters are: Alpabetical for Keyinput, no parameter same as A.      
        :Ie: keysense (same as keysense a) ; keysense A ; keysense c.           
        :Parameters may be typed in upper or lower case.                        
                                                                                
        :A-anykey, B-(A) with buffer flushed, C-anykey caps conversion,         
        :D-(C) buffer flushed, E-alpha-num only with caps conversion,           
        :F-(E) with buffer flushed.                                             
                                                                                 
        :Parameters are: Numerical for Shiftstate                                
        :Ie: keysense 1 ; keysense 3 ; keysense 0;2 ; keysense 341               
                                                                                
        :Parameters may be grouped together, ie: keysense 1 3 5 2, to test for  
        :combinations. The above example would return an errorlevel of 1 if the 
        :Ins, Num, Alt, & Cap keys are all depressed. It would return a level   
        :of 0 if any of those keys were not depressed. It disreguards any other 
        :keys that might be depressed. If you wanted to test that those four    
        :only are pressed, follow the test of those four with a test of the     
        :remaining four useing the 0 parameter. 0 folowed by key parameters     
        :will test for keys not depressed. You could follow that test with      
        :keysense (individual parameters), to see what if any keys are pressed. 
        :Parameters may be separated by {;}, {,}, or spaces. They also may be   
        :chained, ie; keysense 3521 , keysense 52673 etc.                       
                                                                                 
        :9-Returns cumulative errorlevel, ie: 129 if ins key and r-shft pressed, 
        :098 for caps,num,l-shft; 255 for all.                                   
        :Parameter Number and Errorlevel values for each key is:                 
                                                                                
        :Para   Key     Errlvl                                                  
        :                                                                       
        : 1     Ins       128                                                   
        : 2     Caps      64                                                    
        : 3     Num       32                                                    
        : 4     Scrl      16                                                    
        : 5     Alt       8                                                     
        : 6     Ctrl      4                                                     
        : 7     L-Shft    2                                                     
        : 8     R-Shft    1                                                     
        : 9     cumul     total                                                 
        : 0     Not pressed folowed by keys to test.                            

   :Batchfile example for all modes.

echo off
if not [%2]==[] goto multiky
if [%1]==[k] goto showkeys
if [%1]==[K] goto showkeys
if not [%1]==[] goto gdparm
goto entrky
REM ******  Parameter String Passed. *****************
:multiky
keysense %1 %2 %3 %4 %5 %6 %7 %8
if errorlevel 0 if not errorlevel 1 goto multinon
if errorlevel 1 if not errorlevel 2 goto multiok
if errorlevel 2 if not errorlevel 3 goto badstrng
:multiok
set kyst=Has All
REM ***** 0 Parameter used **************
if [%1]==[0] set kyst=Has None
if [%1]==[0] shift
echo 
echo Yes !!! Keys %1%2%3%4%5%6%7%8 Combination %kyst% Depressed
goto end
:multinon
set kyst=Not All
REM ***** 0 Parameter used **************
if [%1]==[0] set kyst=Has Key
if [%1]==[0] shift
echo 
echo No ..... Keys %1%2%3%4%5%6%7%8 Combination %kyst% Depressed.
goto end
:badstrng
echo 
echo Bad Parameter String Passed.
goto end
REM ****** 9 parameter Passed. *****************
REM Cumulative Errorlevel Passed.
:topkey
cls
keysense %1
for %%X in (0 1) do if errorlevel %%X00 set V#=%%X
for %%X in (0 1 2 3 4 5 6 7 8 9) do if errorlevel %V#%%%X0 set V#=%V#%%%X
for %%X in (0 1 2 3 4) do if errorlevel 2%%X0 set V#=2%%X
for %%X in (0 1 2 3 4 5 6 7 8 9) do if errorlevel %V#%%%X set V#=%V#%%%X
for %%X in (0 1 2 3 4 5) do if errorlevel 25%%X set V#=25%%X
echo 
echo 
echo 
echo Errorlevel set to: %V#%
echo Value of keys pressed is: %V#%
goto end
REM ************* Show All Keys Pressed. ****************
REM Call keysense For Each Key.
:showkeys
set kyr=1
set dkey= INS
cls
echo 
echo 
echo 
echo Keys Pressed Are:
echo 
:shky
keysense  %kyr%
if [%nky%]==[1] goto kydispl
set nky=0
:kydispl
if errorlevel 1 if not errorlevel 2 echo %dkey% Key Is Pressed.
if errorlevel 1 if not errorlevel 2 set nky=1
goto sh%kyr%
:sh1
set kyr=2
set dkey=CAPS
goto shky
:sh2
set kyr=3
set dkey= NUM
goto shky
:sh3
set kyr=4
set dkey=SCRL
goto shky
:sh4
set kyr=5
set dkey= ALT
goto shky
:sh5
set kyr=6
set dkey=CTRL
goto shky
:sh6
set kyr=7
set dkey=LSFT
goto shky
:sh7
set kyr=8
set dkey=RSFT
goto shky
:sh8
if [%nky%]==[0] Echo No Keys Were Depressed.
goto end
REM ************* Test For Any Particular Key. **********
:para
:gdparm
for %%X in (1 2 3 4 5 6 7 8) do if [%%X]==[%1] goto %%X
if [%1]==[9] goto topkey
for %%X in (a A b B c C d D e E f F) do if [%%X]==[%1] goto entrky
goto notpara
:1
set dkey=INS
goto work
:2
set dkey=CAPS
goto work
:3
set dkey=NUM
goto work
:4
set dkey=SCRL
goto work
:5
set dkey=ALT
goto work
:6
set dkey=CTRL
goto work
:7
set dkey=LSFT
goto work
:8
set dkey=RSFT
:work
cls
echo 
echo 
echo 
keysense %1
if errorlevel 1 if not errorlevel 2 goto yes
if errorlevel 0 if not errorlevel 1 goto notkey
goto end
:yes
echo Yes %dkey% Key was pressed.
goto end
:notkey
echo No, %dkey% Key was not pressed.
goto end
:notpara
cls
echo Parameter not valid. Legal parameters are: keysense 0-9 or a-f
echo [X] = 1:Ins, 2:Caps, 3:Num, 4:Scrl, 5:Alt, 6:Cntl, 7:Lshft, 8:Rshft.
echo Proper Usage Is: keysense 1; keysense 2; keysense 9; etc. for shiftstate
echo keysense 0 followed by parameters tests for keys not pressed.
echo Proper Usage Is: keysense  (same as a); keysense d; keysense C;s etc.
echo For keyentry. Shiftstate parameters should be separated by {,},{;} or { }.
goto end
:entrky
keysense %1
if errorlevel 0 if not errorlevel 1 goto highkey
for %%X in (0 1) do if errorlevel %%X00 set V#=%%X
for %%X in (0 1 2 3 4 5 6 7 8 9) do if errorlevel %V#%%%X0 set V#=%V#%%%X
for %%X in (0 1 2 3 4) do if errorlevel 2%%X0 set V#=2%%X
for %%X in (0 1 2 3 4 5 6 7 8 9) do if errorlevel %V#%%%X set V#=%V#%%%X
for %%X in (0 1 2 3 4 5) do if errorlevel 25%%X set V#=25%%X
echo 
echo 
echo Errorlevel is: %V#%
goto end
:highkey
keysense
for %%X in (0 1) do if errorlevel %%X00 set V#=%%X
for %%X in (0 1 2 3 4 5 6 7 8 9) do if errorlevel %V#%%%X0 set V#=%V#%%%X
for %%X in (0 1 2 3 4) do if errorlevel 2%%X0 set V#=2%%X
for %%X in (0 1 2 3 4 5 6 7 8 9) do if errorlevel %V#%%%X set V#=%V#%%%X
for %%X in (0 1 2 3 4 5) do if errorlevel 25%%X set V#=25%%X
echo 
echo 
echo Errorlevel is: Extended 0:%V#%
goto end
:end
set V#=
set dkey=
set kyr=
set nky=
set kyst=

        :Batchfile example for shift state use


echo off                                                   
cls                                                        
echo Test.bat                                              
echo Testing for keysense option                           
REM *** Test for scroll key not pressed which returns 0 errlvl if pressed. ****
keysense 04                                                
if errorlevel 0 if not errorlevel 1 goto speed             
REM *** Continue On To Menu Section ****
echo                                                      
echo Scroll Key not depressed. Waiting for Response.       
echo Press A key B key or Esc to exit.                     
REM *** Menu Section ****
:top                                                       
keysense f                                                 
if errorlevel 27 if not errorlevel 28 goto esc             
if errorlevel 65 if not errorlevel 66 goto aky             
if errorlevel 66 if not errorlevel 67 goto bky             
REM *** Key Pressed In Menu Section Not Accounted For ****
echo No good. Not a key tested for.                        
goto top                                                   
REM *** Skipped Menu Section ****
:speed                                                     
echo                                                      
echo Speed key.......Scroll is depressed. Skipped Options. 
goto end                                                   
REM *** Menu Section A Key Pressed ****
:aky                                                       
echo The A key Was Pressed.                                
goto end                                                   
REM *** Menu Section B Key Pressed ****
:bky                                                       
echo The B key Was Pressed.                                
goto end                                                   
REM *** Menu Section Esc. Key Pressed ****
:esc                                                       
echo Esc. Pressed.                                         
:end                                                       
