Autor Beitrag
Soapy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88

Windows 2000
Delphi 2005 Personal
BeitragVerfasst: Di 22.01.08 23:42 
Hallo Delphianer,

Nun...
Mein Problem:
Ich will ein Strategiespiel programmieren (mit einem Freund).
Dabei soll es eine Minimap geben, die man ein und ausblenden kann, indem man auf eine Taste auf der Tastatur (in meinem Fall 'k') drückt.

Jetzt kommt meine Frage:

Man soll die Minimap mit der gleichen Taste aktivieren und deaktivieren können.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if odd(GetAsyncKeyState (VK_Escape)) then
begin
PopUpMenu1.Popup(50,50);
end;
begin
if boolean(getasynckeystate(ord('A'))) then
Scrollbox2.Visible := false;
end;
begin
if boolean(getasynckeystate(ord('A'))) then
Scrollbox2.Visible := true;
end;
end;


Weshalb funktioniert das nicht?
Habt ihr andere Vorschläge wie ich den Tastendruck simulieren kann um das Gleiche zu erreichen?

Ich danke schonmal für die Antworten!
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Mi 23.01.08 00:10 
ausblenden Delphi-Quelltext
1:
Scrollbox2.Visible := not Scrollbox2.Visible;					


Damit wird der Zustand jeweils umgeschaltet.
Soapy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88

Windows 2000
Delphi 2005 Personal
BeitragVerfasst: Mi 23.01.08 08:13 
Danke ich habs gelöst!
Die Lösung post ich nachher!
Muss jetzt zur Schule!

_________________
Linux wird nie das meistinstallierte Betriebssystem sein, wenn man bedenkt, wie oft man Windows neu installieren muss!
Soapy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88

Windows 2000
Delphi 2005 Personal
BeitragVerfasst: Mi 23.01.08 14:27 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
if Scrollbox2.Visible = true then
  begin
  if boolean(getasynckeystate(ord('A'))) then
  Scrollbox2.Visible := false;
  end
else
  begin
  if boolean(getasynckeystate(ord('A'))) then
  Scrollbox2.Visible := true;
  end;


So ist meine Lösung!
Ist warscheinlich nicht sehr elegant aber ich habs gelöst! (Ist mir gestern im Bett noch eingefallen)
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Mi 23.01.08 14:35 
Das ganze kann man dann noch ein wenig optimieren:
ausblenden Delphi-Quelltext
1:
2:
if boolean(getasynckeystate(ord('A'))) then
  Scrollbox2.Visible := not Scrollbox2.Visible;


Mehr brauchts nicht ;) Nun wird mit jedem Tastendruck der Visible-Zustand invertiert / umgeschaltet.