http://www.delphitop.com/html/yingjian/152.html

Delphi驱动方式WINIO模拟按键

作者:admin 来源:未知 日期:2010/2/1 1:14:15 人气:2363 标签:

添加控件 2个button 1个Timer 够了

代码如下:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

const
KBC_KEY_CMD = $64;
KBC_KEY_DATA = $60;
VK_1 = $31;
VK_2 = $32;
VK_3 = $33;
VK_4 = $34;
VK_5 = $35;
VK_6 = $36;
VK_7 = $37;
VK_8 = $38;

var
Form1: TForm1;

implementation

{$R *.dfm}

function InitializeWinIo:Boolean;stdcall;external 'WinIo.dll' name'InitializeWinIo';
function InstallWinIoDriver(pszWinIoDriverPath:PString;IsDemandLoaded:boolean=false):Boolean;stdcall;external 'WinIo.dll' name 'InstallWinIoDriver';
function RemoveWinIoDriver:Boolean;stdcall;external 'WinIo.dll' name 'RemoveWinIoDriver';
function GetPortVal(PortAddr:Word;PortVal:PDWord;bSize:Byte):Boolean;stdcall;external 'WinIo.dll' name 'GetPortVal';
function SetPortVal(PortAddr:Word;PortVal:DWord;bSize:Byte):Boolean;stdcall;external 'WinIo.dll' name 'SetPortVal';
function GetPhysLong(PhysAddr:PByte;PhysVal:PDWord):Boolean;stdcall;external 'WinIo.dll' name 'GetPhysLong';
function SetPhysLong(PhysAddr:PByte;PhysVal:DWord):Boolean;stdcall;external 'WinIo.dll' name 'SetPhysLong';
function MapPhysToLin(PhysAddr:PByte;PhysSize:DWord;PhysMemHandle:PHandle):PByte;stdcall;external 'WinIo.dll' name 'MapPhysToLin';
function UnMapPhysicalMemory(PhysMemHandle:THandle;LinAddr:PByte):Boolean;stdcall;external 'WinIo.dll' name 'UnmapPhysicalMemory';
procedure ShutdownWinIo;stdcall;external 'WinIo.dll' name'ShutdownWinIo';

procedure KBCWait4IBE; //等待键盘缓冲区为空
var
dwVal:DWord;
begin
repeat
GetPortVal($64,@dwVal,1);
until (dwVal and $2)=0;
end;

procedure MyKeyDown(vKeyCoad:Integer);
var
btScancode:DWord;
begin
btScancode:=MapVirtualKey(vKeyCoad, 0);
KBCWait4IBE;
SetPortVal($64, $D2, 1);
KBCWait4IBE;
SetPortVal($60, btScancode, 1);
end;

procedure MyKeyUp(vKeyCoad:Integer);
var
btScancode:DWord;
begin
btScancode:=MapVirtualKey(vKeyCoad, 0);
KBCWait4IBE;
SetPortVal($64, $D2, 1);
KBCWait4IBE;
SetPortVal($64, (btScancode or $80), 1);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled := True;
Button1.Enabled := False;
Button2.Enabled := True;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled := False;
Button1.Enabled := True;
Button2.Enabled := False;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
MyKeyDown(VK_1);
Sleep(50);
MyKeyUp(VK_1);

Sleep(50);
MyKeyDown(VK_2);
Sleep(50);
MyKeyUp(VK_2);

Sleep(50);
MyKeyDown(VK_3);
Sleep(50);
MyKeyUp(VK_3);

Sleep(50);
MyKeyDown(VK_4);
Sleep(50);
MyKeyUp(VK_4);

Sleep(50);
MyKeyDown(VK_5);
Sleep(50);
MyKeyUp(VK_5);

Sleep(50);
MyKeyDown(VK_6);
Sleep(50);
MyKeyUp(VK_6);

Sleep(50);
MyKeyDown(VK_7);
Sleep(50);
MyKeyUp(VK_7);

Sleep(50);
MyKeyDown(VK_8);
Sleep(50);
MyKeyUp(VK_8);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ShutdownWinIo;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
if InitializeWinIo=False then begin
Messagebox(handle,'初始化失败!','提示',MB_OK+MB_IconError)
end;
end;

end.

Delphi驱动方式WINIO模拟按键 可用的更多相关文章

  1. Delphi下利用WinIo模拟鼠标键盘详解 有参考价值

    https://blog.csdn.net/fgrass_163/article/details/6365296 Delphi下利用WinIo模拟鼠标键盘详解 2011年04月26日 21:03:00 ...

  2. C#实现的三种方式实现模拟键盘按键

    1.System.Windows.Forms.SendKeys 组合键:Ctrl = ^ .Shift = + .Alt = % 模拟按键:A private void button1_Click(o ...

  3. Android随笔之——模拟按键操作的几种方式

    前几天转过一篇Android上模拟按键操作.触屏事件的博客,昨天又去找了百度.谷歌了一下,写了一点简单的测试代码,留待不时之需.有需要看之前转载的那篇博客的请看这里→_→转:Android随笔之——使 ...

  4. delphi 向其他程序发送模拟按键

    向其他程序发送模拟按键: 1.用keybd_event: varh : THandle;beginh := FindWindow('TFitForm', '1stOpt - [Untitled1]') ...

  5. linux下如何模拟按键输入和模拟鼠标【转】

    转自:http://www.cnblogs.com/leaven/archive/2010/11/30/1891947.html 查看/dev/input/eventX是什么类型的事件, cat /p ...

  6. C#驱动级模拟按键操作

    C#驱动级模拟按键操作 2013-09-26 03:17 ·AB叔 447 3 <- 点击左侧的数字“攒”一个吧 昨天遇到一个程序自动输入财付通密码的任务. 因为财付通密码控件是有安全保护的,所 ...

  7. android 模拟按键事件

    模拟按键事件可以提高代码的复用性,比如在一个edittext的回车事件里做的一些处理 在该edittext的另一个输入要做相同的处理时,模拟按键事件就非常方便了. 代码很简单,直接上代码: new T ...

  8. android 实现模拟按键

    android 实现模拟按键方法一 通过Runtime实现,代码如下: try { String keyCommand = "input keyevent " + KeyEvent ...

  9. C#获取窗口,模拟按键操作

    C#获取窗口,模拟按键操作,实现计算器模拟操作.首先引用. using System.Runtime.InteropServices; 使用DllImport引入两个函数: // Get a hand ...

随机推荐

  1. phpstorm 快捷键2

    1.跨平台. 2.对PHP支持refactor功能.支持断点调试,支持 Symfony2 和 Yii 的 MVC 视图 3.自动生成phpdoc的注释,非常方便进行大型编程. 4.内置支持Zencod ...

  2. The Python Challenge 闯关笔记

    The Python Challenge : http://www.pythonchallenge.com/ Level 0: 看提示图片中为2**38,计算值为274877906944. Hint: ...

  3. 洛谷P2401 不等数列 题解

    可食用的题目链接 题解: 有题目得:这个题有巧做法而不是暴力模拟.废话 这个题看着像一道dp,因为可以由前一种(数据更小的推出数据更大的)推出后一种. 我们设已经得到了n-1个数的总方法(1~n-1) ...

  4. [易学易懂系列|rustlang语言|零基础|快速入门|(6)|变量绑定]

    [易学易懂系列|rustlang语言|零基础|快速入门|(6)] 有意思的基础知识 变量绑定 我们现在回过头来看看,一些基础知识. 因为理解了前面的重要概念:所有权,借用,生命周期. 我们现在看基础知 ...

  5. linux中shell编辑小技巧

    一.循环1到100 ..};do echo $i done 二.获取100以内的随机值 ] 三.截取字符串 demo= :} #截取3位字符echo ${demo:1} #截取1到最后的字符 希望大家 ...

  6. python3 + Tensorflow + Faster R-CNN训练自己的数据

    之前实现过faster rcnn, 但是因为各种原因,有需要实现一次,而且发现许多博客都不全面.现在发现了一个比较全面的博客.自己根据这篇博客实现的也比较顺利.在此记录一下(照搬). 原博客:http ...

  7. Codeforces Round #569 (Div. 2) B. Nick and Array

    链接: https://codeforces.com/contest/1180/problem/B 题意: Nick had received an awesome array of integers ...

  8. cursor-spacing 软键盘和input的距离

    指定光标与键盘的距离,单位 px .取 input 距离底部的距离和 cursor-spacing 指定的距离的最小值作为光标与键盘的距离. 例: 软键盘和input的距离300px

  9. mysql——非主键自增

    今天遇到一个问题: 要创建一张表,其中我想将ip和date这两列作为一个复合主键,可以通过如下语句修改表结构: alter table tb_name add primary key (字段1,字段2 ...

  10. SpringBoot搭建基于Apache Shiro的权限管理功能

    Shiro 是什么 Apache Shiro是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理等功能: 认证 - 用户身份识别,常被称为用户“登录”: 授权 - 访问控制: 密码加密 ...