首页 > Windows开发 > 详细

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

时间:2014-07-29 10:45:26      阅读:498      评论:0      收藏:0      [点我收藏+]

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.


WinAPI: GetKeyNameText - 根据键盘消息获取按键名称,布布扣,bubuko.com

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

原文:http://www.cnblogs.com/pinksoft/p/3873750.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!