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. 2019-11-29-dotnet-文件读写务必注意事项

    title author date CreateTime categories dotnet 文件读写务必注意事项 lindexi 2019-11-29 08:34:43 +0800 2019-10- ...

  2. linux把用户添加到组

    使用 usermod 命令 将现有的用户添加到多个次要组或附加组 # usermod -a -G GroupName UserName id 命令查看输出 # id UserName 用户添加到多个次 ...

  3. 脚本_通过进程与端口判断myslq服务

    #!bin/bashif [[ $port -eq 1 || $porcess -eq 2 ]];then  #通过条件判断端口和进程执行的返回值.     echo "mysql is s ...

  4. 021-Zabbix4.2对IIS监控摸索记录

    Zabbix是很强大,但是相关的细节技术文档貌似很少,摸索之路就显得异常难. 度娘搜了下,关于Zabbix对IIS的监控资料确实有,确实也讲如何操作了,但是细细按照对方的要求操作下,总是缺数据,no ...

  5. php set_magic_quotes_runtime() 函数过时解决方法

    PHP5.3中 bool set_magic_quotes_runtime ( bool $new_setting )函数过时.把函数: set_magic_quotes_runtime($newse ...

  6. cmd命令删除文件夹或文件

    删除空文件夹rd /s/q "D:\Program Files\afish" 删除里面的文件del /a/f/q "D:\Program Files\afish\123. ...

  7. SSH加密传输

    数据传输安全的要满足的要求: (1)消息的发送方能够确定消息只有预期的接收方可以解密(不保证第三方无法获得,但保证第三方无法解密) (2)消息的接收方可以确定消息是由谁发送的(消息的接收方可以确定消息 ...

  8. redux 中的 redux-thunk(中间件)

    前言 空闲时间把redux中的redux-thunk中间件回顾下,因为以前没有写博客的习惯,都怪自己太年轻,好了 其实:      redux的核心概念其实很简单:将需要修改的state都存入到sto ...

  9. pyqt5-QTDesigner--控件操作

    Edit菜单       编辑小伙伴.用鼠标直接拖       编辑控件---样式等等. 点击需要编辑的控件--->   信号与槽 先用鼠标从控件往外拖---> --->选中相应的信 ...

  10. 《数据结构(C语言)》苏小红 课本案例

    期末了,赶紧复习一波,手打一份书上的代码以便随时查阅 第二章: //顺序表存储结构 #define MAXSIZE 100 typedef struct { Elemtype *elemt; int ...