Autor Beitrag
Denis{MAD}
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Mi 30.08.06 19:23 
Hallo

ich habe ein folgendes Problem:
ich arbeite an einem Rennspiel und da es langsam einfach zu viele Knöpfe gibt die man im Spiel braucht, möchte ich dem Spieler die gelegenheit geben die Steuerung anzupassen.

Folgendes habe ich mir überlegt:
ich werde "edit" Felder benutzen, OnKlick soll also das "edit" Feld ausgewählt werden und auf das Ereigniss OnKeyDown gewartet werden, dann wird der KeyCode (var Key) übergeben, nun muss ich dem Benutzer aber zeigen, dass alles geklappt hat, denn wenn ich da einfach nur eine Zahl im edit Feld ausgebe ist es unmöglich nachzuvollziehen welchen Knopf man nun ausgewählt hat.

Also die Frage:
Wie bekomme ich die Variable KEY von dem OnKeyDown event in ein für den "normalen" Menschen verständliches Zeichen umgewandelt?
Ich weiß, dass es Key Codes (z.B.: Key_Escape) gibt. Kann ich vieleicht den Key code durch eine Funktion in einen String umwandeln (wäre blöd wenn ich jetzt für jeden Key Code eine if Abfrage machen müsste)?

Bin für jeden Beitrag dankbar
Denis

P.S.: die Chr() Funktion habe ich schon ausprobiert, doch dies klappt nur bei Buchstaben, NUM PAD Zahlen werden nämlich nicht richtig ausgegeben...
Ironwulf
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: Mi 30.08.06 19:41 
ich hab das ganze mal gemacht gehabt kann aber sein das da noch ein paar fehlen
ausblenden volle Höhe 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:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
  If Key = $08 Then Taste:= 'BackSpace';
  If Key = $09 Then Taste:= 'Tab';
  If Key = $0D Then Taste:= 'Enter';
  If Key = $10 Then Taste:= 'Shift';
  If Key = $11 Then Taste:= 'Strg';
  If Key = $12 Then Taste:= 'Alt';
  If Key = $14 Then Taste:= 'CapsLock';
  If Key = $1B Then Taste:= 'Esc';
  If Key = $20 Then Taste:= 'Space';
  If Key = $25 Then Taste:= 'Links';
  If Key = $26 Then Taste:= 'Up';
  If Key = $27 Then Taste:= 'Rechts';
  If Key = $28 Then Taste:= 'Down';
  If Key = $30 Then Taste:= '0';
  If Key = $31 Then Taste:= '1';
  If Key = $32 Then Taste:= '2';
  If Key = $33 Then Taste:= '3';
  If Key = $34 Then Taste:= '4';
  If Key = $35 Then Taste:= '5';
  If Key = $36 Then Taste:= '6';
  If Key = $37 Then Taste:= '7';
  If Key = $38 Then Taste:= '8';
  If Key = $39 Then Taste:= '9';
  If Key = $41 Then Taste:= 'A';
  If Key = $42 Then Taste:= 'B';
  If Key = $43 Then Taste:= 'C';
  If Key = $44 Then Taste:= 'D';
  If Key = $45 Then Taste:= 'E';
  If Key = $46 Then Taste:= 'F';
  If Key = $47 Then Taste:= 'G';
  If Key = $48 Then Taste:= 'H';
  If Key = $49 Then Taste:= 'I';
  If Key = $4A Then Taste:= 'J';
  If Key = $4B Then Taste:= 'K';
  If Key = $4C Then Taste:= 'L';
  If Key = $4D Then Taste:= 'M';
  If Key = $4E Then Taste:= 'N';
  If Key = $4F Then Taste:= 'O';
  If Key = $50 Then Taste:= 'P';
  If Key = $51 Then Taste:= 'Q';
  If Key = $52 Then Taste:= 'R';
  If Key = $53 Then Taste:= 'S';
  If Key = $54 Then Taste:= 'T';
  If Key = $55 Then Taste:= 'U';
  If Key = $56 Then Taste:= 'V';
  If Key = $57 Then Taste:= 'W';
  If Key = $58 Then Taste:= 'X';
  If Key = $59 Then Taste:= 'Y';
  If Key = $5A Then Taste:= 'Z';
  If Key = $60 Then Taste:= 'Num 0';
  If Key = $61 Then Taste:= 'Num 1';
  If Key = $62 Then Taste:= 'Num 2';
  If Key = $63 Then Taste:= 'Num 3';
  If Key = $64 Then Taste:= 'Num 4';
  If Key = $65 Then Taste:= 'Num 5';
  If Key = $66 Then Taste:= 'Num 6';
  If Key = $67 Then Taste:= 'Num 7';
  If Key = $68 Then Taste:= 'Num 8';
  If Key = $69 Then Taste:= 'Num 9';
  If Key = $6A Then Taste:= 'Num *';
  If Key = $6B Then Taste:= 'Num +';
  If Key = $6C Then Taste:= 'Num ,';
  If Key = $6D Then Taste:= 'Num -';
  If Key = $6E Then Taste:= 'Num ,';
  If Key = $6F Then Taste:= 'Num /';
  If Key = $71 Then Taste:= 'F1';
  If Key = $71 Then Taste:= 'F2';
If Key = $72 Then Taste:= 'F3';
If Key = $73 Then Taste:= 'F4';
If Key = $74 Then Taste:= 'F5';
If Key = $75 Then Taste:= 'F6';
If Key = $76 Then Taste:= 'F7';
If Key = $77 Then Taste:= 'F8';
If Key = $78 Then Taste:= 'F9';
If Key = $79 Then Taste:= 'F10';
If Key = $7A Then Taste:= 'F11';
If Key = $7B Then Taste:= 'F12';
If Key = $7C Then Taste:= 'F13';
If Key = $7D Then Taste:= 'F14';
If Key = $7E Then Taste:= 'F15';
If Key = $7F Then Taste:= 'F16';
If Key = $80 Then Taste:= 'F17';
If Key = $81 Then Taste:= 'F18';
If Key = $82 Then Taste:= 'F19';
If Key = $83 Then Taste:= 'F20';
If Key = $84 Then Taste:= 'F21';
If Key = $85 Then Taste:= 'F22';
If Key = $86 Then Taste:= 'F23';
If Key = $87 Then Taste:= 'F24';
  If Key = $90 Then Taste:= 'NumLock';
  If Key = $BA Then Taste:= 'Ü';
  If Key = $BB Then Taste:= '+';
  If Key = $BC Then Taste:= ',';
  If Key = $BD Then Taste:= '-';
  If Key = $BE Then Taste:= '#';
  If Key = $BF Then Taste:= 'Ö';
  If Key = $C0 Then Taste:= '?';
  If Key = $DB Then Taste:= '´';
  If Key = $DC Then Taste:= '^';
  If Key = $DE Then Taste:= 'Ä';
  If Key = $E2 Then Taste:= '<';


EDIT

fehlenden delphibeendungstag hinzugefügt

EDIT2

wenn bedarf besteht kann ich auch noch den größten teil in die andre richtung posten also, Taste in Key
Denis{MAD} Threadstarter
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Mi 30.08.06 20:25 
Hast dir aber viel Arbeit gemacht ^_^

Danke für die schnelle Antwort, ich werds gleich mal versuchen.

Aber eine frage hab ich noch: wieso stehen bei dir ein "$" zeichen vor den Zahlen (z.B.: $01)?

Ich hatte das so benutzt: if key=87 then wird die Funktion für "W" ausgeführt
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mi 30.08.06 20:29 
Das $-Zeichen heißt nur, dass darauf keine Dezimal-Zahlen folgen, sondern Hexadezimalzahlen.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Denis{MAD} Threadstarter
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Mi 30.08.06 21:11 
Danke für die schnellen Antworten funktioniert jetzt wunderbar!!!^_^
cuejo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP
Delphi 7 Personal und 2005 PE
BeitragVerfasst: Mi 30.08.06 22:50 
Warum sucht ihr nicht bevor ihr fragt oder euch unnötig arbeit macht? Tja selbst schuld:
ausblenden Delphi-Quelltext
1:
Taste:=ShortCutToText(Key);					

_________________
Computer sind dumm, aber fleißig. Deshalb arbeite ich so gerne damit.
Ironwulf
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: Mi 30.08.06 23:09 
weil es so keinen spaß macht ;D

und alle gehn damit auch nich z.b. ^ oder DRUCK und die linke pfeiltaste heißt linksbündig das is auch unschön
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Mi 30.08.06 23:19 
@Ironwuf: lIch würd es wenigstens in eine case-Bedingung packen. Sieht besser aus und vorallem wenn du ein Key hast wird der Rest nicht mehr abgefragt (ode wenigstens mit else)...


greetz

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
Ironwulf
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 733
Erhaltene Danke: 2



BeitragVerfasst: Mi 30.08.06 23:59 
stimmt natürlich wusst nur nich das man case auch auf word vars anwenden kann...

ausblenden volle Höhe 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:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
case Key of
  $08: Taste:= 'BackSpace';  
  $09: Taste:= 'Tab';  
  $0D: Taste:= 'Enter';  
  $10: Taste:= 'Shift';  
  $11: Taste:= 'Strg';  
  $12: Taste:= 'Alt';  
  $14: Taste:= 'CapsLock';  
  $1B: Taste:= 'Esc';  
  $20: Taste:= 'Space';  
  $25: Taste:= 'Links';  
  $26: Taste:= 'Up';  
  $27: Taste:= 'Rechts';  
  $28: Taste:= 'Down';  
  $30: Taste:= '0';  
  $31: Taste:= '1';  
  $32: Taste:= '2';  
  $33: Taste:= '3';  
  $34: Taste:= '4';  
  $35: Taste:= '5';  
  $36: Taste:= '6';  
  $37: Taste:= '7';  
  $38: Taste:= '8';  
  $39: Taste:= '9';  
  $41: Taste:= 'A';  
  $42: Taste:= 'B';  
  $43: Taste:= 'C';  
  $44: Taste:= 'D';  
  $45: Taste:= 'E';  
  $46: Taste:= 'F';  
  $47: Taste:= 'G';  
  $48: Taste:= 'H';  
  $49: Taste:= 'I';  
  $4A: Taste:= 'J';  
  $4B: Taste:= 'K';  
  $4C: Taste:= 'L';  
  $4D: Taste:= 'M';  
  $4E: Taste:= 'N';  
  $4F: Taste:= 'O';  
  $50: Taste:= 'P';  
  $51: Taste:= 'Q';  
  $52: Taste:= 'R';  
  $53: Taste:= 'S';  
  $54: Taste:= 'T';  
  $55: Taste:= 'U';  
  $56: Taste:= 'V';  
  $57: Taste:= 'W';  
  $58: Taste:= 'X';  
  $59: Taste:= 'Y';  
  $5A: Taste:= 'Z';  
  $60: Taste:= 'Num 0';  
  $61: Taste:= 'Num 1';  
  $62: Taste:= 'Num 2';  
  $63: Taste:= 'Num 3';  
  $64: Taste:= 'Num 4';  
  $65: Taste:= 'Num 5';  
  $66: Taste:= 'Num 6';  
  $67: Taste:= 'Num 7';  
  $68: Taste:= 'Num 8';  
  $69: Taste:= 'Num 9';  
  $6A: Taste:= 'Num *';  
  $6B: Taste:= 'Num +';  
  $6C: Taste:= 'Num ,';  
  $6D: Taste:= 'Num -';  
  $6E: Taste:= 'Num ,';  
  $6F: Taste:= 'Num /';  
  $71: Taste:= 'F1';  
  $71: Taste:= 'F2';  
  $72: Taste:= 'F3';  
  $73: Taste:= 'F4';  
  $74: Taste:= 'F5';  
  $75: Taste:= 'F6';  
  $76: Taste:= 'F7';  
  $77: Taste:= 'F8';  
  $78: Taste:= 'F9';  
  $79: Taste:= 'F10';  
  $7A: Taste:= 'F11';  
  $7B: Taste:= 'F12';  
  $7C: Taste:= 'F13';  
  $7D: Taste:= 'F14';  
  $7E: Taste:= 'F15';  
  $7F: Taste:= 'F16';  
  $80: Taste:= 'F17';  
  $81: Taste:= 'F18';  
  $82: Taste:= 'F19';  
  $83: Taste:= 'F20';  
  $84: Taste:= 'F21';  
  $85: Taste:= 'F22';  
  $86: Taste:= 'F23';  
  $87: Taste:= 'F24';  
  $90: Taste:= 'NumLock';  
  $BA: Taste:= 'Ü';  
  $BB: Taste:= '+';  
  $BC: Taste:= ',';  
  $BD: Taste:= '-';  
  $BE: Taste:= '#';  
  $BF: Taste:= 'Ö';  
  $C0: Taste:= '?';  
  $DB: Taste:= '´';  
  $DC: Taste:= '^';  
  $DE: Taste:= 'Ä';  
  $E2: Taste:= '<'
end;
cuejo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 142

Win XP
Delphi 7 Personal und 2005 PE
BeitragVerfasst: Do 31.08.06 18:15 
Ich weiß zwar nicht welches Delphi du hast aber in D7 wird ^ als "ZIRKUMFLEX" und die linke Pfeiltaste als "links" dargestellt. "DRUCK" klappt bei mir auch nicht aber in solchen fällen kann man dem
ausblenden Delphi-Quelltext
1:
Taste:=ShortCutToText(Key);					

dann ja immer noch eine case-anweisung folgen lassen :lol: . Aber naja, wenn du spaß am tippen hast :roll: .

_________________
Computer sind dumm, aber fleißig. Deshalb arbeite ich so gerne damit.
Denis{MAD} Threadstarter
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Do 31.08.06 20:22 
ok das ist genau das was ich gesucht hab eine delphi funktion (wobei das mit der schönen funktion von Ironwulf ja auch klappt)

also zum Suchen: hab gesucht nur nix gefunden, wusste auch nicht so recht welche Suchbegriffe ich verwenden sollte...