WinAPI: GetKeyNameText - 根据键盘消息获取按键名称

为什么80%的码农都做不了架构师?>>>   hot3.png

本例效果图:

WinAPI: GetKeyNameText - 根据键盘消息获取按键名称_第1张图片
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure MyMsg(var msg: TWMKeyDown); message WM_KEYDOWN;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Canvas.Font.Size := 24;
  Canvas.Font.Style := [fsBold];
  Canvas.Font.Color := clRed;
  Canvas.Brush.Color := clWhite;
end;

procedure TForm1.MyMsg(var msg: TWMKeyDown);
var
  buf: array[0..31] of Char;
  rect: TRect;
  str: string;
begin
  {获取}
  GetKeyNameText(msg.KeyData, buf, Length(buf));
  {画出来}
  str := buf;
  rect := ClientRect;
  Canvas.FillRect(rect);
  Canvas.TextRect(rect, str, [tfSingleLine, tfCenter, tfVerticalCenter]);
  inherited;
end;

end.

 
 
 
 
 

 

 

  

转载于:https://my.oschina.net/hermer/blog/320355

你可能感兴趣的:(WinAPI: GetKeyNameText - 根据键盘消息获取按键名称)