TIP: Click on subject to list as thread! ANSI
echo: delphi
to: ALL
from: BRYAN SMITH
date: 1996-06-07 22:21:00
subject: Toggling Numlock

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)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.