Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Tastatur multilingual (https://www.delphipraxis.net/6385-tastatur-multilingual.html)

Ghostwalker 9. Jul 2003 08:27


Tastatur multilingual
 
Also..folgendes Problem:

Ich suche nach einer Möglichkeit, herauszufinden welche Tastencodes welches Zeichen ergeben. Das Problem dabei ist das das ganze möglichst im mehrsprachigen Umfeld funktionieren sollte.

Beispiel:
deutsche Tastatur:
# = 191

englische Tastatur:

# = Shift+51

Weiß jemand wie man das möglichst einfach ermitteln kann ?

Tiefflieger 10. Jul 2003 17:19

Re: Tastatur multilingual
 
meinst du die ascii-codes? die ist doch international:

http://www.asciitable.com/

Ghostwalker 19. Jul 2003 08:52

Re: Tastatur multilingual
 
Nein...wenn dann brauch ich Ansi, da windows an und für sich mit ASCII nix anfangen kann (darstellung).

Dagon 19. Jul 2003 09:19

Re: Tastatur multilingual
 
hier findest du eine ANSI-tabelle.

Ghostwalker 19. Jul 2003 22:13

Re: Tastatur multilingual
 
Du verstehst mich falsch.

In der Windows-API gibts eine Funktion vkkeyscan. diese gibt mir für ein bestimmtes Zeichen den virtuellen Tastencode..und zwar abhängig von der eingestelleten Tastatur (deutsch,englisch, chinesisch usw..). Was ich brauche wär eine Umkehrfunktion dazu. Ich hab den virtuellen Keycode (z.B. VK_Shift+'1') und brauche dazu das entsprechende Zeichen, auch wieder abhängig von der eingestellten Tastatur.


Ich will es eigentlich vermeiden hunderte von Konstanten-Units zu bauen:)

Gast 19. Jul 2003 23:03

Re: Tastatur multilingual
 
Hier mal ein Auszug aus dem PSDK ... wie wäre es denn erstmal mit dem Nachschauen in der Dokumentation? :mrgreen: :

Zitat:

ToAscii
The ToAscii function translates the specified virtual-key code and keyboard state to the corresponding character or characters. The function translates the code using the input language and physical keyboard layout identified by the keyboard layout handle.

To specify a handle to the keyboard layout to use to translate the specified code, use the ToAsciiEx function.

ToAsciiEx
The ToAsciiEx function translates the specified virtual-key code and keyboard state to the corresponding character or characters. The function translates the code using the input language and physical keyboard layout identified by the input locale identifier.

ToUnicode
The ToUnicode function translates the specified virtual-key code and keyboard state to the correspondingUnicodecharacter or characters.

To specify a handle to the keyboard layout to use to translate the specified code, use the ToUnicodeEx function.

ToUnicodeEx
The ToUnicodeEx function translates the specified virtual-key code and keyboard state to the corresponding Unicode character or characters.

Ghostwalker 20. Jul 2003 08:10

Re: Tastatur multilingual
 
oh..hm...öhm...ja...wer lesen kann ist klar im Vorteil. :oops: :oops: :oops:

Ghostwalker 20. Jul 2003 10:45

Re: Tastatur multilingual
 
so..nach etwas tüftelei hab ich nun die Routine fertig. Sie ermittelt zu einem Virtuellen Tastencode das entsprechende Zeichen. Auch die Shift-Taste wird hierbei berücksichtigt.

Delphi-Quellcode:
function VKToChar(Key:smallint;Shift:boolean=false;layout:HKL=0):string;
var
  kb : TKeyboardState;
  VK : UINT;
  scan : UINT;
  hs : array [0..255] of char;
  erg : Integer;
begin
  result := '';
  fillchar(hs,sizeof(hs),0);
//Wenn kein Keyboardlayout angegeben dann das des aktuellen Threads nehmen
  if (layout = 0) then
    layout := GetKeyboardlayout(0);
//virtuellen Tastencode der Taste ermitteln
  VK := VKKeyScan(chr(key));
//Scan-Code ermitteln
  scan := MapVirtualKey(VK,0);
//Keyboard-State ermitteln und entsprechend setzten
  GetKeyboardState(kb);
  kb[key] := (kb[VK] or $80);
  if shift then
    kb[VK_SHIFT] := KB[VK_SHIFT] OR $80;
  SetKeyboardState(kb);
//Zeichen ermitteln
  erg := toAsciiEx(VK,scan,kb,@hs,0,layout);
  if (erg > 0) then
    result := StrPas(HS)
  else
    result := 'ERROR';
end;
Somit ist es möglich zu ermitteln welches zeichen entsteht wenn ich beispielsweise SHIFT+1 drücke ('!'). Leider funktioniert das nicht mit der ALT GR-Taste.


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:41 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz