{----------------------------------------------------------------------------- ---> Project DelphiWorks <--- Version 1.4 ----------------------------------------------------------------------------- Unit: dwKeyboard.pas Description: Keyboard helpers Author: Codehunter Works Release: 1.4 State: Stable Date: 16.08.2004 Created: 14.02.2005 History: n/a -----------------------------------------------------------------------------} unit dwKeyboard; interface function dwGetCapslock: Boolean; function dwGetNumLock: Boolean; function dwGetScrollLock: Boolean; procedure dwEmptyKeyboardQueue; procedure dwSetCapsLock(const CapsLockOn: Boolean); procedure dwSetNumLock(const NumLockOn: Boolean); procedure dwSetScrollLock(const ScrollLockOn: Boolean); implementation uses Messages, Windows; function dwGetCapslock: Boolean; var KS: TKeyboardState; begin GetKeyboardState(KS); result:= (KS[VK_CAPITAL]<>0); end; function dwGetNumLock: Boolean; var KS: TKeyboardState; begin GetKeyboardState(KS); result:= (KS[VK_NUMLOCK]<>0); end; function dwGetScrollLock: Boolean; var KS: TKeyboardState; begin GetKeyboardState(KS); result:= (KS[VK_SCROLL]<>0); end; {----------------------------------------------------------------------------- Procedures -----------------------------------------------------------------------------} procedure dwEmptyKeyboardQueue; var Msg: TMsg; begin while PeekMessage(Msg, 0, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE or PM_NOYIELD) do; end; procedure dwSetCapsLock(const CapsLockOn: Boolean); var KS: TKeyboardState; begin GetKeyboardState(KS); if CapsLockOn then KS[VK_CAPITAL]:= 1 else KS[VK_CAPITAL]:= 0; SetKeyboardState(KS); end; procedure dwSetNumLock(const NumLockOn: Boolean); var KS: TKeyboardState; begin GetKeyboardState(KS); if NumLockOn then KS[VK_NUMLOCK]:= 1 else KS[VK_NUMLOCK]:= 0; SetKeyboardState(KS); end; procedure dwSetScrollLock(const ScrollLockOn: Boolean); var KS: TKeyboardState; begin GetKeyboardState(KS); if ScrollLockOn then KS[VK_SCROLL]:= 1 else KS[VK_SCROLL]:= 0; SetKeyboardState(KS); end; end.