Hallöle
Hab da ma n Problem:
Ich hab da ein Lauflicht Programm das wie folgt aussieht:
[code=delphi]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TKeyType = (ktCapsLock, ktNumLock, ktScrollLock);
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private-Deklarationen }
stufe: integer;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure SetLedState(KeyCode: TKeyType; bOn: Boolean);
var
KBState: TKeyboardState;
Code: Byte;
begin
case KeyCode of
ktScrollLock: Code := VK_SCROLL;
ktCapsLock: Code := VK_CAPITAL;
ktNumLock: Code := VK_NUMLOCK;
end;
GetKeyboardState(KBState);
if (Win32Platform = VER_PLATFORM_WIN32_NT) then
begin
if Boolean(KBState[Code]) <> bOn then
begin
keybd_event(Code,
MapVirtualKey(Code, 0),
KEYEVENTF_EXTENDEDKEY,
0);
keybd_event(Code,
MapVirtualKey(Code, 0),
KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP,
0);
end;
end
else
begin
KBState
Code:
:= Ord(bOn);
SetKeyboardState(KBState);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
timer1.Enabled := true;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
case stufe of
1:
begin
SetLedState(ktNumLock, TRUE); // NumLock off
SetLedState(ktCapsLock, FALSE); // CapsLock off
SetLedState(ktScrollLock, FALSE); // ScrollLock off
stufe := 2;
end;
2:
begin
SetLedState(ktNumLock, False); // NumLock off
SetLedState(ktCapsLock, TRUE); // CapsLock off
SetLedState(ktScrollLock, FALSE); // ScrollLock off
stufe := 3;
end;
3:
begin
SetLedState(ktNumLock, False); // NumLock off
SetLedState(ktCapsLock, FALSE); // CapsLock off
SetLedState(ktScrollLock, TRUE); // ScrollLock off
stufe := 4;
end;
4:
begin
SetLedState(ktNumLock, False); // NumLock off
SetLedState(ktCapsLock, TRUE); // CapsLock off
SetLedState(ktScrollLock, FALSE); // ScrollLock off
stufe := 1;
end;
else stufe := 1;
end;
timer1.Enabled := FALSE;
timer1.Enabled := TRUE;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SetLedState(ktNumLock, TRUE); // NumLock off
SetLedState(ktCapsLock, FALSE); // CapsLock off
SetLedState(ktScrollLock, FALSE); // ScrollLock off
end;
end.
Wenn ich es starte is alles fein und funzt 1 a
ABER wenn ich es minimiere oder ein anderes Programm in den Vordergrund hole dann läft das ganz komisch und die lämpchen flackern ganz anders.
Was ist das?
Gruß
Nickless