home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2002 November
/
Chip_2002-11_cd1.bin
/
zkuste
/
delphi
/
kompon
/
d456
/
KEYLED.ZIP
/
KeyLed.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2002-07-29
|
3KB
|
114 lines
//---------------------------------------------------------------------
//
// KeyLed component
//
// Copyright (c) 2001-2002 WINSOFT
//
//---------------------------------------------------------------------
unit KeyLed;
interface
uses Classes;
type
TKeyLed = class(TComponent)
private
function GetAbout: String;
procedure SetAbout(const Value: String);
function GetCapsLock: Boolean;
procedure SetCapsLock(Value: Boolean);
function GetNumLock: Boolean;
procedure SetNumLock(Value: Boolean);
function GetScrollLock: Boolean;
procedure SetScrollLock(Value: Boolean);
published
property About: String read GetAbout write SetAbout stored False;
property CapsLock: Boolean read GetCapsLock write SetCapsLock stored False;
property NumLock: Boolean read GetNumLock write SetNumLock stored False;
property ScrollLock: Boolean read GetScrollLock write SetScrollLock stored False;
end;
procedure Register;
implementation
uses Windows, SysUtils;
function GetKeyState(Key: Integer): Boolean;
var Buffer: TKeyboardState;
begin
GetKeyboardState(Buffer);
Result := Buffer[Key] <> 0;
end;
procedure SetKeyState(Key: Integer; TurnOn: Boolean);
var Buffer: TKeyboardState;
begin
case Win32Platform of
VER_PLATFORM_WIN32_WINDOWS: // Win95/98/ME
begin
GetKeyboardState(Buffer);
Buffer[Key] := Ord(TurnOn);
SetKeyboardState(Buffer)
end;
VER_PLATFORM_WIN32_NT: // WinNT/2000/XP
begin
if GetKeyState(Key) <> TurnOn then
begin
keybd_event(Key, $45, KEYEVENTF_EXTENDEDKEY, 0); // simulate key press
keybd_event(Key, $45, KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP, 0); // simulate key release
end;
end
end;
end;
function TKeyLed.GetAbout: String;
begin
Result := 'Version 1.1, Copyright (c) 2001-2002 WINSOFT, http://www.winsoft.sk';
end;
procedure TKeyLed.SetAbout(const Value: String);
begin
end;
function TKeyLed.GetCapsLock: Boolean;
begin
Result := GetKeyState(VK_CAPITAL)
end;
procedure TKeyLed.SetCapsLock(Value: Boolean);
begin
if not (csLoading in ComponentState) then
SetKeyState(VK_CAPITAL, Value);
end;
function TKeyLed.GetNumLock: Boolean;
begin
Result := GetKeyState(VK_NUMLOCK)
end;
procedure TKeyLed.SetNumLock(Value: Boolean);
begin
if not (csLoading in ComponentState) then
SetKeyState(VK_NUMLOCK, Value);
end;
function TKeyLed.GetScrollLock: Boolean;
begin
Result := GetKeyState(VK_SCROLL)
end;
procedure TKeyLed.SetScrollLock(Value: Boolean);
begin
if not (csLoading in ComponentState) then
SetKeyState(VK_SCROLL, Value);
end;
procedure Register;
begin
RegisterComponents('System', [TKeyLed]);
end;
end.