delphi 按键测试
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 按键测试的更多相关文章
- ADSL_自动拨号源码(Delphi),已经测试通过
下载地址: http://files.cnblogs.com/lwm8246/ADSL_%E8%87%AA%E5%8A%A8%E6%8B%A8%E5%8F%B7.rar
- [转]Delphi 控件属性和事件
常用[属性] Action:该属性是与组件关联的行为,允许应用程序集中响应用户命令 Anchors:与组件连接的窗体的位置点 Align:确定组件的对齐方式 AutoSize:确定组件是否自动调整其大 ...
- Delphi经验总结(1)
先人的DELPHI基础开发技巧 ◇[DELPHI]网络邻居复制文件 uses shellapi; copyfile(pchar('newfile.txt'),pchar('//computername ...
- 【小技巧】9针USB转串口简易连通性测试,附25针转9针
Part 1 前言 最近用SecureCRT连接串口,因为是笔记本用的USB转串口,好多次出现安装驱动OK,连接上了,但是没有串口打印.无法进行控制的问题:所以不清楚是USB串口的驱动问题,还是转接用 ...
- delphi 调用QQ邮箱发送邮件
procedure TForm1.FormCreate(Sender: TObject); begin try IdSMTP1.AuthenticationType := atLogin; IdSMT ...
- delphi 各版本的特性
delphi 各新版本特性收集 Delphi XE6新增了一些特性并增强了原有的功能,主要有以下几个方面: IDE(整合开发环境) Internet XML(扩展标记语言) Compiler( ...
- 《FPGA全程进阶---实战演练》第七章 让按键恢复平静
1基础理论部分 A:“怎么按键按下去之后,结果不正常?”,B:“按键你消抖了吗?”A:“消什么抖,还要消抖?”, B:“先检测按键变化,然后消抖过滤波动信号,最后输出稳定信号”,A:“我好像漏掉了什 ...
- Python3 tkinter基础 event keysym 查看按键的按键名
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 【嵌入式】FS2410非操作系统外围资源测试
在刚接触FS2410时,其实这个测试也没有多大意义,但是对于以后来说,当一个产品做成功时,产品测试还是一个必须经过的一个阶段,所以这个流程还是有必要走一下! 在非操作系统下,主要进行RTC测试,按键测 ...
随机推荐
- Maven中添加镜像
Maven库在天朝的下载速度实在是感人,所以添加镜像之后速度会提升很多. 在maven的settings.xml 文件里配置mirrors的子节点,添加如下mirror <mirror> ...
- cocos2dx 3.17.1 导演类
进入导演类的头文件,首先看到的是一些头文件的引用:CCPlatformMacros(适配),CCRef(继承的父类),CCVector(3.0以后的新向量),CCScene(场景),CCMath(数学 ...
- cocos-lua3.17 Lua tablrView工具类
local MyTableView = class("MyTableView") MyTableView.__index = MyTableView MyTableView.pro ...
- ajax提交表单向后台发送数据
Ajax提交表单 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- MNIST机器学习进阶
# -*- coding: utf-8 -*-"""Created on Wed Oct 17 08:49:28 2018 @author: Administrator& ...
- 在jsp里面 当鼠标元素触发onmouseover时,旁边出现一个浮动且跟随鼠标的div ,移开消失
JSP页面 : <label onmouseover="showLongStrlog(window.event, '<list:seqnum></list:seqnu ...
- MongoDB知识点拾遗梳理
MongoDB数据库安装: >apt-get install mongodb 0.MongoDB状态查看.启动.停止 >/etc/init.d/mongodb status或s ...
- 使用VB6读取数据库资源并发送邮件(原创)
Private Sub Form_Load() Call conndb End Sub Private Function conndb() Dim cn As New ADODB.Connection ...
- vue-resource+element upload上传(遇到formData总是变为object格式)
文件上传这种业务需求很常见,但是最近用了element,仔细看了文档,按照demo写了上传,与后台传参调取接口时,控制台总是显示未获取到文件,想了又想,发现一开始思路就跑遍了... 写此博记录下遇到的 ...
- 【TLV】非递归TLV数据解析
#include <stdio.h> #define X_LEN_OF_TAG_MAX ( 2 ) #define X_LEN_OF_LEN_MAX ( 2 ) struct st_tlv ...