Problem Detecting Key Toggle
Keywords: numlock keytoggleget
Question:
Iconized WIL Interpreter window doesn't seem to detect NUMLOCK state changes.My WIL batch file looks like this:
;------------------------------------- While KeyToggleGet(@NUMLOCK) == @OFF WinTitle(``, `Thinks NUMLOCK OFF`) Delay(1) EndWhile Message(``, `Detected NUMLOCK ON`) ;-------------------------------------Steps to Repeat Problem:Additional Notes:
- From the keyboard, set NUMLOCK off.
- Execute the WIL batch file. The WIL Interpreter becomes iconized. WIL Interpreter title becomes "Thinks NUMLOCK OFF".
- From the keyboard, set NUMLOCK on. Unexpectedly, the state change is not detected and nothing happens.
As soon as the WIL Interpreter goes from an ICON to a NORMAL window, the NUMLOCK state change is detected.
Is there a work-around, possibly involving a Windows API call?
Answer:
WinBatch can only "see" the numlock change if Windows tells it. Windows will only inform WinBatch that it has changed if WinBatch is either the active window or may soon become it (as in moving the mouse over the window).In 32 bit Windows, each application can have its own view of the status of the toggles, so you can only really see and set your own view. Consequently, WinBatch cannot necessarily detect the Key Toggle for a specific application, or read that view for the KeyToggleSet.
On DOS based systems, like 16-bit Windows, this function will return the keys state for ALL applications.
Article ID: W13094Filename: KeyToggleGet and Problem Detecting Key Toggle.txt