Lock test is dual 16bit Dos and 32bit Windows executable utility which examines status of keyboard indicators NumLock, CapsLock, ScrollLock, and returns the detected status in errorlevel and as a digit 0 or 1 on standard output.
Argument should start with uppercase or lowercase letter
N,C or S, it may be optionaly prefixed with slash
/ or dash -. For instance
locktest Scroll
, locktest /scrollLock
, locktest -s
.
Utility displays help text when wrong argument was provided.
Lock Test can be used in batch scripts for instance to warn the user that keyboard is in unexpected state, or to control the running PC service with Lock keys without having the monitor switched on.
Dual utility means that locktest.exe
works both in 16bit Dos and in
32bit or 64bit Windows. The Dos version is compiled to MZ file
locktdos.exe
and then it will be embedded to Windows version
, i.e. to PE file locktest.exe
as its stub.
Dos stub is used by loader when the Windows subsystem is not available.
Both versions have the same functionality, their similar part are shared via Header division.
Keeping the source of both Dos and Windows versions in this one file provokes conflict in their application interfaces dosapi.htm and winapi.htm, which both define macros with the same names. That is why I suppress warning
W2512 Overwriting macro "StdOutput" previously defined at "dosapi.htm"{218}.
Num
, Caps
or Scroll
.euroasm locktest.htm
locktest.exe
EUROASM UNICODE=OFF, AUTOSEGMENT=ON, NOWARN=2512 %HelpText %SET 13,10, \ 'Program: locktest.exe version %^DATE.',13,10, \ 'Licence: Public domain by vitsoft.',13,10, \ 'Format: %%^FORMAT (dual Dos | Windows console application).',13,10, \ 'Function: Test NumLock | CapsLock | ScrollLock keyboard status.',13,10, \ 'Parameter:Num | Caps | Scroll, optionally prefixed with dash | slash.',13,10,\ 'Output: Digit 0 | 1, errorlevel 0 | 1.',13,10, \ 'Example: locktest ScrollLock or locktest -s',13,10, \ 0
locktDos.exein real DOS or in NTVDM emulation from 32bit MS Windows.
locktDos PROGRAM FORMAT=MZ, MODEL=SMALL, WIDTH=16, Entry=Main: INCLUDE dosapi.htm %HelpExp %SET2 %HelpText ; Delayed expansion of %^FORMAT variable. HelpText DB %HelpExp ; Final definition of HelpText in MZ variant. Digit DB '0' ; Output character 0 or 1. Main: PROC ; Entry point of Dos version. PUSH PARA#HelpText ; [PSP] is adressed with ES, POP DS ; [DATA] will be addressed with DS. GetArg 1 ; Use DosAPI macro to get 1st argument to SI,CX. JC Help: ; Skip of none was found. .0x2D: ; Labels .0x2D: | .0x2F: are used when argument starts with dash | slash. .0x2F: SEGES:LODSB ; The first character should be one of / - N C S n c s. OR AL,0x20 ; Convert letters N C S to n c s. Dispatch AL,0x2D,0x2F,'n','c','s' Help: StdOutput HelpText ; Display Help$ text when the argument is not valid. TerminateProgram Errorlevel=8 .c: MOV BL,0x40 ; CapsLock Flag mask. JMP Test: .s: MOV BL,0x10 ; ScrollLock Flag mask. JMP Test: .n: MOV BL,0x20 ; NumLock Flag mask. Test: DosAPI INT=16h,AH=2; Returns keyboard flags in AL (in fact it's BiosAPI). AND AL,BL ; Test the requested lock flag. JZ ReturnAL: ; Skip when the flag is reset. MOV AL,1 ; Prepare output errorlevel and digit. ReturnAL: OR [Digit],AL ; AL is now 0 or 1. StdOutput Digit, Size=1, Eol=Yes ; Write 0 or 1 on StdOutput. TerminateProgram Errorlevel=AL ; Terminate with errorlevel 0 or 1. ENDPROC Main: ENDPROGRAM locktDos
locktdos.exeas its MZ stub.
locktest PROGRAM FORMAT=PE, WIDTH=32,ENTRY=Main:, \ ICONFILE=, STUBFILE="locktDos.exe" INCLUDE winapi.htm, winsgui.htm IMPORT GetKeyState,LIB=user32.dll %HelpExp %SET2 %HelpText ; Delayed expansion of %^FORMAT variable. HelpText DB %HelpExp ; Final definition of HelpText in PE variant. Digit DB '0' ; Output character 0 or 1. Main: PROC ; Entry point of Win version. GetArg 1 ; Use WinAPI macro to get 1st argument to ESI,ECX. JC Help: ; Abort if none was found. .0x2D: ; Labels .0x2D: | .0x2F: are used when argument starts with dash | slash. .0x2F: LODSB ; The first character should be one of / - N C S n c s. OR AL,0x20 ; Convert letters N C S to n c s. Dispatch AL,0x2D,0x2F,'n','c','s' Help: StdOutput HelpText ; Display Help$ text when the argument is not valid. TerminateProgram Errorlevel=8 .c: MOV EAX,VK_CAPITAL JMP Test: .s: MOV EAX,VK_SCROLL JMP Test: .n: MOV EAX,VK_NUMLOCK Test: WinAPI GetKeyState, EAX ; Return lock state of virtual key. AND EAX,1 ; Isolate the LSbit. OR [Digit],AL ; Modify the digit for StdOutput. StdOutput Digit, Size=1,Eol=Yes ; Write 0 or 1 on StdOut. TerminateProgram Errorlevel=EAX ; Terminate with errorlevel 0 or 1. ENDPROC Main: ENDPROGRAM locktest