Back in February, I asked how to toggle Numlock from within a program, in
order to force the keypad to be available for numeric entry. Nobody
replied, so perhaps some people don't know. Here is what I have learned ...
uses WinProcs ;
Procedure ToggleNumLock(ToggleOn : boolean) ;
const
NumLock = 144 ;
var
KS : TKeyboardState ;
begin
GetKeyboardState(KS) ;
if ToggleOn then KS[NumLock] := KS[NumLock] or $01 { set low bit }
else KS[NumLock] := KS[NumLock] and $FE ; { clear low bit }
SetKeyboardState(KS) ;
end ;
Notes ...
This toggles both the numlock state and the keyboard light.
KS is an array of 256 bytes, indexed by the Windows Virtual Key VK_****
constants. If the high-order bit is 1, that key is held down : if 0, then
it is up. For toggleable keys, the low order bit indicates the toggle
state, 1 = on.
Capslock = 20, Numlock = 144, Scrolllock = 145.
This is WINAPI stuff. To make life easy, Borland did not bother to index
TKeyboardState in the on-line help, but Get- and SetKeyboardState are
indexed.
--- PPoint 2.00
---------------
* Origin: Kingston, Canada (1:249/109.11)
|