Autor Beitrag
De-Roma
Hält's aus hier
Beiträge: 8

WinXP - HOME
d7
BeitragVerfasst: Fr 09.07.04 10:37 
ich experimentiere gerade damit ein Image mittels der Tasten w s a d über das Formular zu bewegen leider wird beim onkeypress event immer nur eine Taste erkannt und diagonale bewegungen sind nicht möglich... wer kann mir sagen wie ich eine (echte) diagonale bewegung hin bekomme ???
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Fr 09.07.04 10:59 
Hi,

z.B mittels GetKeyboardState und dann mit KeybState die Tasten abfragen.
Bsp: www.swissdelphicente...showcode.php?id=1622
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Fr 09.07.04 11:06 
Geht nicht. Das Problem haben auch andere. Du kannst die Umschalttaste, die Strg Taste und die Alt Taste in Kombination mit einer Normaltaste drücken, aber keine zwei Normaltasten gleichzeitig. Auch wenn du zwei Tasten drückst, so kannst du es nicht steuern, daß du ein mal die erste und dan die zweite Taste ausliest. Es wird immer die erste Taste genommen.

Wenn du also eine diagonale Bewegung haben willst, dann mußt du dir was anderes überlegen. Eine Möglichkeit wäre die Zehnertastatur, mit der du NOSW (Himmelsrichtungen) durch 8624 lösen könntest und NoSoSwNw durch 9317.

_________________
Gruß
Martin
Alstar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 827



BeitragVerfasst: Fr 09.07.04 11:42 
Hi!

Geht das garnicht oder nur mit Delphi nicht??

Alstar
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Fr 09.07.04 11:58 
Zitat:
Geht nicht. Das Problem haben auch andere. Du kannst die Umschalttaste, die Strg Taste und die Alt Taste in Kombination mit einer Normaltaste drücken, aber keine zwei Normaltasten gleichzeitig.


Bei mir geht's auf jedenfall. Gerade getestet. du auch?
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Fr 09.07.04 12:13 
@toms

So richtig hat mich das noch nicht überzeugt. Das hier funktioniert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  If ((GetKeyState(VK_F5)      AND 128)=128) and
     ((GetKeyState(ord('8'))   AND 128)=128)
    then
      ShowMessage('F5+8 Pressed');
end;


das auch

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  If ((GetKeyState(ord('7'))   AND 128)=128) and
     ((GetKeyState(ord('8'))   AND 128)=128)
    then
      ShowMessage('7+8 Pressed');
end;


das nicht mehr

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  If ((GetKeyState(ord('w'))   AND 128)=128) and
     ((GetKeyState(ord('d'))   AND 128)=128)
    then
      ShowMessage('w+d Pressed');
end;


Zumindest bei mir nicht.

_________________
Gruß
Martin
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Fr 09.07.04 12:15 
und so?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;  
  Shift: TShiftState);  
begin  
  If ((GetKeyState(ord('W'))   AND 128)=128) and  
     ((GetKeyState(ord('D'))   AND 128)=128)  
    then  
      ShowMessage('w+d Pressed');  
end;
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Fr 09.07.04 12:31 
So klappts.

_________________
Gruß
Martin
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Fr 09.07.04 12:34 
Habe noch einen Code geschrieben, um das Image mit allen 2-er (a-s-d-w) Kombinationen zu bewegen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
function MoveShape(key1, key2: Char; dx, dy: Integer; Image: TImage): Boolean;
begin
  Result := False;
  if ((GetKeyState(Ord(key1)) and 128) = 128) and
    ((GetKeyState(Ord(key2)) and 128) = 128) then
  begin
    Image.Left := Image.Left + dx;
    Image.Top  := Image.Top + dy;
    Result := True;
  end;
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
const
  DELTA = 2;
begin
  if not MoveShape('A', 'W', - DELTA, - DELTA, Image1) then
    if not MoveShape('W', 'D', + DELTA, - DELTA, Image1) then
      if not MoveShape('S', 'D', + DELTA, + DELTA, Image1) then
        if not MoveShape('S', 'A', - DELTA, + DELTA, Image1) then
          case Key of
            'a': Image1.Left := Image1.Left - DELTA;
            's': Image1.Top  := Image1.Top + DELTA;
            'd': Image1.Left := Image1.Left + DELTA;
            'w': Image1.Top  := Image1.Top - DELTA;
          end;
end;
FAlter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 192

Win XP Home
Turbo Delphi 2006 (Win32), C# (VS 2008 Prof.), Java (Eclipse), PHP
BeitragVerfasst: Fr 09.07.04 13:33 
Ich kann nicht sagen warum, aber ich nehme dazu immer GetAsyncKeyState.
DelphiFreund
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 120

Win XP
D7 Enterprise
BeitragVerfasst: Fr 09.07.04 14:18 
Schau mal hier:

www.delphi-forum.de/...27128&highlight=

Gruß DelphiFreund