Autor Beitrag
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 20.12.06 18:12 
Ich habe das Problem, einen ScanCode, den man zB. bei OnKeyDown übergeben bekommt, in einen ASCII-Buchstaben umzuwandeln.
Ich hab da schon nen Teil geschafft, jedoch sehe ich keine Möglichkeit die AltGr-Taste abzufragen, und die Abfrage für Caps-Lock (VK_Capital) geht auch nicht, weshalb sich dann einige Buchstaben nicht eingeben ließen. Mein Code bis jetzt:
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 SCtoVK(key:Word):Word;
begin
  result:=MapVirtualKey(key,2);
  if result=0 then
    result:=key
  else
  begin
    if (GetAsyncKeyState(VK_LShift)<0) or (GetAsyncKeyState(VK_RShift)<0) or (GetAsyncKeyState(VK_Capital)<0) then
    begin
      case key of
        48:result:=Integer('?'); //0
        49:result:=Integer('!'); //1
        50:result:=Integer('"'); //2
        51:result:=Integer('§'); //3
        52:result:=Integer('$'); //4
        53:result:=Integer('%'); //5
        54:result:=Integer('&'); //6
        55:result:=Integer('/'); //7
        56:result:=Integer('('); //8
        57:result:=Integer(')'); //9
        else result:=Integer(AnsiUpperCase(STring(Chr(result)))[1])
      end;
    end
    else
      result:=Integer(AnsiLowerCase(STring(Chr(result)))[1])
  end;
end;

Gibt es eine Windows-Funktion dafür? (schön wärs :roll: )
Oder wie kann ich die AltGR-Taste und Caps-Lock abfragen?

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 20.12.06 19:52 
Hallo,

dort hatte ich mal was dazu geschrieben:
Statusbar bei Editor ( NUM | CAPS)

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
jakobwenzel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mi 20.12.06 19:56 
Hmmm, so funktioniert das nur solang Caps-Lock noch gedrückt wird (wie auch bei meiner Version) :cry:

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Mi 20.12.06 20:24 
Beim OnKeyDown & ~Up-Event werden diese Tasten als "Shift"-Tasten mit übergeben. Also wenn man z.B. abfragen will, ob die Altgr-Taste gedrückt ist, erkennt man das an:

ausblenden Delphi-Quelltext
1:
if (ssAlt in Shift) and (ssCtrl in Shift) then...					

(Strl + Alt sind gedrückt, aber es können auch noch weitere Tasten wie z.B. Alt gedrückt sein)

bzw.

ausblenden Delphi-Quelltext
1:
if Shift = [ssAlt, ssCtrl] then...					

(Strl + Alt sind gedrückt und es können keine weitere Tasten wie z.B. Alt gedrückt sein)

Shift ist vollgendermaßen deklariert (was welche Option ist, dürfte klar sein)
ausblenden Delphi-Quelltext
1:
2:
  TShiftState = set of (ssShift, ssAlt, ssCtrl,
    ssLeft, ssRight, ssMiddle, ssDouble);


Ob man irgendwie unterscheiden kann, ob AltGr oder Alt+Strg gedürckt ist, ka.
jakobwenzel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mi 20.12.06 20:29 
Ach ja, des hatt ich übersehn, weil die eigentliche Behandlung in ner eigenen Prozedur steht... :roll:

Dann sollte das so weit laufen, aber wie geht das jetz mit Caps-Lock?
Mitloggen wanns gedrückt wird bringts ja auch nich, weils kann ja vorher schon aktiviert sein :roll:

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Mi 20.12.06 20:39 
Dürfte das gleiche sein, wie mit AltGr - Delphi gibt dir das nur als Shift zurück, da es ja aufs gleiche hinausläuft.

Allerdings wird man das ggf. über die eine Abfrage herausbekommen (GetKeyState). Vlt. pfuscht da Delphin nicht dazwischen und u kommst daran....
jakobwenzel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mi 20.12.06 20:41 
Nö, das wird leider nich als shift zurückgegeben. Und mit GetKeyState/GetAsyncKeyState gehts nur solange die Taste noch gedrückt ist (wie normales shift).

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
jakobwenzel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Mi 20.12.06 21:08 
OK, ich habs da gefunden.
Für die mit dem gleichen Prob hier mein Code:
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:
function SCtoASCII(key:Word;shift:TshiftState):Word;
begin
  result:=MapVirtualKey(key,2);
  if result=0 then
    result:=key
  else
  begin
    if (ssShift in Shift) or ((GetKeyState(VK_CAPITAL) AND 1) = 1) then
    begin
      case key of
        48: result:=Integer('?'); //0
        49: result:=Integer('!'); //1
        50: result:=Integer('"'); //2
        51: result:=Integer('§'); //3
        52: result:=Integer('$'); //4
        53: result:=Integer('%'); //5
        54: result:=Integer('&'); //6
        55: result:=Integer('/'); //7
        56: result:=Integer('('); //8
        57: result:=Integer(')'); //9
        220:result:=Integer('°'); //^
        219:result:=Integer('?'); //ß
        221:result:=Integer('`'); //9
        188:result:=Integer(';'); //,
        190:result:=Integer(':'); //.
        189:result:=Integer('_'); //-
        191:result:=Integer('''');//#
        187:result:=Integer('*'); //+
        else result:=Integer(AnsiUpperCase(STring(Chr(result)))[1])
      end;
    end
    else
      if (ssCTRL in shift) and (ssAlt in shift) then
      begin
        case result of
          55: result:=Integer('{'); //7
          56: result:=Integer('['); //8
          57: result:=Integer(']'); //9
          58: result:=Integer('}'); //0
          223:result:=Integer('\'); //ß
          43: result:=Integer('~'); //+
          81: result:=Integer('@'); //Q
          69: result:=Integer('€'); //E
          else result:=0
        end;
      end
      else
        result:=Integer(AnsiLowerCase(STring(Chr(result)))[1])
  end;
end;

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.