unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Imaging.pngimage, Vcl.ExtCtrls,
Vcl.StdCtrls, Vcl.Buttons, Vcl.ComCtrls, Vcl.DBCtrls, System.StrUtils; type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDblClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
procedure Remote(key: Integer);
public
{ Public declarations }
procedure WndProc(var Message: TMessage); override;
procedure MyCopyData(var message: TWMCopyData); message WM_COPYDATA;
end; var
Form1: TForm1; implementation {$R *.dfm} procedure SendMyKeyDown(key: Integer);
var
data: TCopyDataStruct;
str: string;
begin
str:= '下'+ IntToStr(key);
data.dwData := ;
data.cbData := Length(str) + ;
data.lpData := PChar(str);
SendMessage(Application.MainForm.Handle, WM_COPYDATA, , LongWord(@data));
end; procedure SendMyKeyUp(key: Integer);
var
data: TCopyDataStruct;
str: string;
begin
str:= '上'+ IntToStr(key);
data.dwData := ;
data.cbData := Length(str) + ;
data.lpData := PChar(str);
SendMessage(Application.MainForm.Handle, WM_COPYDATA, , LongWord(@data));
end; procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Visible := False;
Button2.Visible := False;
Button3.Visible := False;
Button4.Visible := False; SendMyKeyDown(Ord('A'));
SendMyKeyUp(Ord('A'));
end; procedure TForm1.Button2Click(Sender: TObject);
begin
Button1.Visible := False;
Button2.Visible := False;
Button3.Visible := False;
Button4.Visible := False; SendMyKeyDown(VK_CONTROL);
SendMyKeyUp(VK_CONTROL);
end; procedure TForm1.Button3Click(Sender: TObject);
begin
Button1.Visible := False;
Button2.Visible := False;
Button3.Visible := False;
Button4.Visible := False; SendMyKeyDown(VK_SHIFT);
SendMyKeyUp(VK_SHIFT);
end; procedure TForm1.Button4Click(Sender: TObject);
begin
Button1.Visible := False;
Button2.Visible := False;
Button3.Visible := False;
Button4.Visible := False; SendMyKeyDown(VK_MENU);
SendMyKeyUp(VK_MENU);
end; procedure TForm1.FormCreate(Sender: TObject);
begin
self.KeyPreview := True;
end; procedure TForm1.FormDblClick(Sender: TObject);
begin
Label1.Caption := '';
Label2.Caption := '';
Label3.Caption := '';
Label4.Caption := ''; Button1.Visible := not Button1.Visible;
Button2.Visible := not Button2.Visible;
Button3.Visible := not Button3.Visible;
Button4.Visible := not Button4.Visible;
end; procedure TForm1.MyCopyData(var message: TWMCopyData);
var
data: PCopyDataStruct;
str: string;
key: Integer;
begin
data := message.CopyDataStruct;
str := string(PChar(data.lpData));
if StartsText('下', str) then
begin
key := StrToInt(StringReplace(str, '下', '', []));
keybd_event(key, MapVirtualKey(key, ), , );
end
else
begin
key := StrToInt(StringReplace(str, '上', '', []));
keybd_event(key, MapVirtualKey(key, ), KEYEVENTF_KEYUP, );
end;
end; procedure TForm1.Remote(key: Integer);
begin
//这里就是接收到的按键
end; procedure TForm1.WndProc(var Message: TMessage);
begin
inherited; case Message.Msg of
WM_KEYDOWN:
begin
Label1.Caption := Format('KeyDown: %d - %d', [message.WParam, message.LParam]);
Remote(message.WParam);
end;
WM_KEYUP:
begin
Label2.Caption := Format('KeyUp: %d - %d', [message.WParam, message.LParam]);
Remote(message.WParam);
end;
WM_SYSKEYDOWN:
begin
Label3.Caption := Format('SysKeyDown: %d - %d', [message.WParam, message.LParam]);
Remote(message.WParam);
end;
WM_SYSKEYUP:
begin
Label4.Caption := Format('SysKeyUp: %d - %d', [message.WParam, message.LParam]);
Remote(message.WParam);
end;
end;
end; end.

delphi 按键测试的更多相关文章

  1. ADSL_自动拨号源码(Delphi),已经测试通过

    下载地址: http://files.cnblogs.com/lwm8246/ADSL_%E8%87%AA%E5%8A%A8%E6%8B%A8%E5%8F%B7.rar

  2. [转]Delphi 控件属性和事件

    常用[属性] Action:该属性是与组件关联的行为,允许应用程序集中响应用户命令 Anchors:与组件连接的窗体的位置点 Align:确定组件的对齐方式 AutoSize:确定组件是否自动调整其大 ...

  3. Delphi经验总结(1)

    先人的DELPHI基础开发技巧 ◇[DELPHI]网络邻居复制文件 uses shellapi; copyfile(pchar('newfile.txt'),pchar('//computername ...

  4. 【小技巧】9针USB转串口简易连通性测试,附25针转9针

    Part 1 前言 最近用SecureCRT连接串口,因为是笔记本用的USB转串口,好多次出现安装驱动OK,连接上了,但是没有串口打印.无法进行控制的问题:所以不清楚是USB串口的驱动问题,还是转接用 ...

  5. delphi 调用QQ邮箱发送邮件

    procedure TForm1.FormCreate(Sender: TObject); begin try IdSMTP1.AuthenticationType := atLogin; IdSMT ...

  6. delphi 各版本的特性

    delphi 各新版本特性收集 Delphi XE6新增了一些特性并增强了原有的功能,主要有以下几个方面:   IDE(整合开发环境)   Internet XML(扩展标记语言) Compiler( ...

  7. 《FPGA全程进阶---实战演练》第七章 让按键恢复平静

    1基础理论部分 A:“怎么按键按下去之后,结果不正常?”,B:“按键你消抖了吗?”A:“消什么抖,还要消抖?”,  B:“先检测按键变化,然后消抖过滤波动信号,最后输出稳定信号”,A:“我好像漏掉了什 ...

  8. Python3 tkinter基础 event keysym 查看按键的按键名

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  9. 【嵌入式】FS2410非操作系统外围资源测试

    在刚接触FS2410时,其实这个测试也没有多大意义,但是对于以后来说,当一个产品做成功时,产品测试还是一个必须经过的一个阶段,所以这个流程还是有必要走一下! 在非操作系统下,主要进行RTC测试,按键测 ...

随机推荐

  1. selenium多窗口切换定位

    from selenium import webdriverimport unittest,time,refrom selenium.webdriver.common.keys import Keys ...

  2. matlab json文件解析 需要下载一个jsonlab-1.5

    % facebookX24.m clc; addpath('C:\Program Files\MATLAB\R2015b\toolbox\jsonlab-1.5'); % read .json jso ...

  3. pytorch 读数据接口 制作数据集 data.dataset

    [吐槽] 啊,代码,你这个大猪蹄子 自己写了cifar10的数据接口,跟官方接口load的数据一样, 沾沾自喜,以为自己会写数据接口了 几天之后,突然想,自己的代码为啥有点慢呢,这数据集不大啊 用了官 ...

  4. sqlserver智能提示插件-sql prompt(9.4.6)的安装及注册流程

    官网下在地址:https://www.red-gate.com/products/sql-development/sql-prompt/ CSDN下载地址(对应的版本是9.4.6,其中包含安装包和注册 ...

  5. Linux 驱动——Button驱动4(fasync)异步通知

    button_drv.c驱动文件: #include <linux/module.h>#include <linux/kernel.h>#include <linux/f ...

  6. 利用 SPICE 分析理解心电图前端中的右腿驱动

      [导读] 心电图(ECG)学是一门将心脏离子去极(ionic depolarization) 后转换为分析用可测量电信号的科学.模拟电子接口到电极/患者设计中最为常见的难题之一便是优化右腿驱动 ( ...

  7. 安装系统后IP配置问题

    1.配置静态IP 在/etc/sysconfig/network-script/ifcfg-eth0 文件,网卡管理文件.修改为静态IP.IPADDR.网关.掩码等 同一台机器上的网卡不能配置在同一网 ...

  8. 使用Docker搭建LNMP开发环境

    1.什么是Docker Docker 使用 Google 公司推出的 Go 语言 进行开发实现,基于 Linux 内核的 cgroup,namespace,以及 AUFS 类的 Union FS 等技 ...

  9. padding填充属性

    内边距属性: 设置元素的内容与边框之间的距离. 分4个方向(上右下左): padding-top padding-right padding-bottom padding-left 说明:值不能为负值 ...

  10. python学习6---字典合并

    1.针对python3版本 d1={'gao':1,'luo':2} d2={'liu':3,'jia':4} dictMerged1=dict(d1,**d2) print(dictMerged1) ...