Autor Beitrag
juKx
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 45

WinXp Pro Sp2
Delphi 7 Enterprise Edition
BeitragVerfasst: Mo 13.02.06 10:59 
hi,

ich möchte in der procedure onkeypress mit den pfeiltasten arbeiten...wie geht das?!

thx im Voraus!
WolfB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 39

WinXP Professional
Delphi 7
BeitragVerfasst: Mo 13.02.06 11:23 
hi!
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if key=vk_up then close;
end;


vk_up steht für die pfeiltaste nach oben. die anderen lassen sich daraus ableiten als vk_down für runter, vk_left für links und vk_right für rechts.
danach, wo nun das close steht kannste schreiben was bei der taste ausgeführt werden soll.
juKx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 45

WinXp Pro Sp2
Delphi 7 Enterprise Edition
BeitragVerfasst: Mo 13.02.06 15:13 
Danke für die schnelle Antwort! Es klappt perfekt.
juKx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 45

WinXp Pro Sp2
Delphi 7 Enterprise Edition
BeitragVerfasst: Mo 13.02.06 15:29 
Hi,

sry aber ich wollte das auch gleich mal ausprobieren aber da steht als Fehlermeldung: Inkompatible Typen wenn ich das so mache wie du besschreiben hasT!?
Danny87
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Mo 13.02.06 15:33 
das problem hatte ich auch mal, weiss aber nicht mehr wie ichs gelöst hab... :oops:


muss es unbedingt OnKeyPress sein oder kanns auch OnKeyDown sein?
In OnKeyDown funktionierts nämlich


gruss daniel
juKx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 45

WinXp Pro Sp2
Delphi 7 Enterprise Edition
BeitragVerfasst: Mo 13.02.06 15:37 
hi,

mh....oder wie kann ich das machen wenn es keine procedure von keypress oder onkeydown ist..also allgemein...bsp: procedure rechnen..bla und dann das überprüfen ob der key gedrückt wird? befehle?
Danny87
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Mo 13.02.06 15:41 
Das geht mit GetAsyncKeyState.

ausblenden Delphi-Quelltext
1:
if GetAsyncKeyState(vk_up) < 0 then DoSomething					
Danny87
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Mo 13.02.06 15:44 
mach dafür am besten eine endlosschleife in der du alles abfragst.
etwa so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
while true do
  begin
  if GetAsyncKeyState(vk_up) < 0 then ShowMessage('Pfeil hoch wurde gedrueckt');
  Application.ProcessMessages;
  end;


das Application.ProcessMessages; ist wichtig, weil sonst dein Prog in der endlosschleife "hängt".


gruss daniel
juKx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 45

WinXp Pro Sp2
Delphi 7 Enterprise Edition
BeitragVerfasst: Mo 13.02.06 15:47 
hi,
thx jetzt klappt alles...vielen dank
Danny87
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Mo 13.02.06 15:52 
hab noch was vergessen:

du benötigst mit der schleife einen extra abbruchbefehl, da das programm erst beendet wird wenn die schleife "aufhört zu laufen".

aus der schleife kommst du mit Break; raus.
Mach das einfach für vk_escape oder so.


gruss daniel
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 13.02.06 15:54 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
while true do   
  begin   
  if GetAsyncKeyState(vk_up) < 0 then ShowMessage('Pfeil hoch wurde gedrueckt');   
  Application.ProcessMessages;   
  end;
Das ist wohl ein schlechter Witz, oder :shock:??

_________________
We are, we were and will not be.
Danny87
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Mo 13.02.06 15:56 
Ach quatsch, das is en guter Witz ;-)

Warum meinste?
Ich benutz das oft in Spielen.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 13.02.06 16:17 
Schonmal die Prozessorauslastung angeguckt, wenn man z.B. so ne Schleife in einem ButtonClick startet? Dann bleibt zum Spielen nicht mehr viel übrig...

_________________
We are, we were and will not be.
Danny87
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Mo 13.02.06 16:23 
für gewöhnlich liegt die dann bei knapp 100%, aber ich lass ja nich einfach so ne schleife laufen. ich mach das ungefähr so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
while bIsRunning do
  begin
  CalcAI;
  KeyboardHandler;
  MessageHandler;
  DrawScene;
  Application.ProcessMessages;
  end;


so in ungefähr. wie genau, mag ich hier nicht preisgeben, weil ich sehr lange gebraucht hab um eine einigermaßen effiziente
spieleschleife zu coden ;-)


gruss daniel
Danny87
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Di 14.02.06 11:50 
hab noch was vergessen.... ich benutze die schleife in verbindung mit DirectX.
Meine (neueren) Spiele laufen alle flüssig auf PCs ab 600 MHz.



gruss daniel