was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

39 Visitors Online


 
...einen virtuellen Tastatur-Code in einen ASCII Code umwandeln?
Autor: P. Below
Homepage: http://www.teamb.com
[ Tip ausdrucken ]  

Tip Bewertung (9):  
     


{
  Typically you would get the scancode needed from the
  lparam of a WM_KEYDOWN message.
  If you are trying to work from an OnKeyDown handler
  here you don't have that either,
  so you have to fall back on MapVirtualKey.
  The keystate array is obtained from GetKeyboardstate.
}


{: Obtain the character that will result from the virtual key
     passed in.
   @param vkey is the virtual key code, e.g. Key parameter of an
     OnKeyDown handler.
   @returns the character or '' if the key does not result in a
     character. On rare occasions the function may return two
     characters, e.g. if an accent key is pressed followed by another
     character that does not have an accented version. }

function GetCharFromVKey(vkey: Word): string;
var
  
keystate: TKeyboardState;
  retcode: Integer;
begin
  
Win32Check(GetKeyboardState(keystate));
  SetLength(Result, 2);
  retcode := ToAscii(vkey,
    MapVirtualKey(vkey, 0),
    keystate, @Result[1],
    0);
  case retcode of
    
0: Result := ''; // no character
    
1: SetLength(Result, 1);
    2:;
    else
      
Result := ''; // retcode < 0 indicates a dead key
  
end;
end;

procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  
label1.Caption := GetCharFromVKey(Key);
end;

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners