delphi模拟按键精灵自动控制PDF页面自动扩边的源代码
需要的环境:Adobe Acrobat 7.0 Professional 和 Quite Imposing Plus 1.5d Acrobat plugin (qi160.exe)
程序界面:

unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, RzTray, Vcl.ExtCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Button2: TButton;
Label2: TLabel;
Edit2: TEdit;
edtDownNum: TEdit;
Label3: TLabel;
Label4: TLabel;
BalloonHint1: TBalloonHint;
TrayIcon1: TTrayIcon;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses shellapi;
{$R *.dfm}
function Matchstrings(Source, pattern: String): Boolean;
var
pSource: array[0..255] of Char;
pPattern: array[0..255] of Char;
function MatchPattern(element, pattern: PChar): Boolean;
function IsPatternWild(pattern: PChar): Boolean;
begin
Result := StrScan(pattern, '*') <> nil;
if not Result then
Result := StrScan(pattern, '?') <> nil;
end;
begin
if 0 = StrComp(pattern, '*') then
Result := True
else if (element^ = Chr(0)) and (pattern^ <> Chr(0)) then
Result := False
else if element^ = Chr(0) then
Result := True
else
begin
case pattern^ of
'*':
if MatchPattern(element, @pattern[1]) then
Result := True
else
Result := MatchPattern(@element[1], pattern);
'?':
Result := MatchPattern(@element[1], @pattern[1]);
else
if element^ = pattern^ then
Result := MatchPattern(@element[1], @pattern[1])
else
Result := False;
end;
end;
end;
begin
StrPCopy(pSource, Source);
StrPCopy(pPattern, pattern);
Result := MatchPattern(pSource, pPattern);
end; {匹配字符串函数}
{从磁盘中搜索指定类型的所有文件}
procedure FindFiles(ASourceDir, SearchFileType: String; var List: TStrings);
var
FileRec: TSearchrec;
Sour: String;
begin
Sour := ASourceDir;
if Sour[length(Sour)] <> '\' then
Sour := Sour + '\';
if FindFirst(Sour + '*.*', faAnyfile, FileRec) = 0 then
{循环}
repeat
if ((FileRec.Attr and faDirectory) <> 0) then
begin
if (FileRec.Name <> '.') and (FileRec.Name <> '..') then //找到目录
begin
FindFiles(Sour + FileRec.Name, SearchFileType, List);
end;
end
else //找到文件
begin
if Matchstrings(AnsiLowerCase(FileRec.Name), SearchFileType) then
begin
List.Add(Sour + FileRec.Name);
end; {拷贝所有类型的文件}
end;
until FindNext(FileRec) <> 0;
FindClose(FileRec);
end; {从磁盘中搜索指定类型的所有文件}
function ForceForegroundWindow(hwnd: HWND): Boolean;
const
SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
var
ForegroundThreadID: DWORD;
ThisThreadID: DWORD;
timeout: DWORD;
begin
if IsIconic(hwnd) then
ShowWindow(hwnd, SW_RESTORE);
// if not IsWindowVisible(hwnd) then
// ShowWindow(hwnd, SW_SHOWNOACTIVATE);
if GetForegroundWindow = hwnd then
Result := True
else
begin
if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion > 4)) or
((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
((Win32MajorVersion > 4) or ((Win32MajorVersion = 4) and
(Win32MinorVersion > 0)))) then
begin
Result := False;
ForegroundThreadID := GetWindowThreadProcessID(GetForegroundWindow, nil);
ThisThreadID := GetWindowThreadPRocessId(hwnd, nil);
if AttachThreadInput(ThisThreadID, ForegroundThreadID, True) then
begin
BringWindowToTop(hwnd);
SetForegroundWindow(hwnd);
AttachThreadInput(ThisThreadID, ForegroundThreadID, False);
Result := (GetForegroundWindow = hwnd);
end;
if not Result then
begin
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout, 0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
TObject(0), SPIF_SENDCHANGE);
BringWindowToTop(hWnd);
SetForegroundWindow(hWnd);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0,
TObject(timeout), SPIF_SENDCHANGE);
end;
end
else
begin
BringWindowToTop(hWnd);
SetForegroundWindow(hwnd);
end;
Result := (GetForegroundWindow = hwnd);
end;
end;
procedure pressButtonDown(btn:Thandle);
begin
postMessage(btn,WM_LBUTTONDOWN,VK_LBUTTON,0); // MK_LBUTTON 0231028E $1f0028
postMessage(btn,WM_LBUTTONUP,0,0);
postMessage(btn,WM_LBUTTONDOWN,VK_LBUTTON,0); // MK_LBUTTON 0231028E $1f0028
postMessage(btn,WM_LBUTTONUP,0,0);
end;
function closeAboutWindow():boolean;
var
rundemo,btnHandle: Cardinal;
begin
result:=false;
rundemo:= findwindow('#32770','About Quite Imposing 1.6 (EN)');
if rundemo<>0 then
begin
SetForegroundWindow(rundemo);
btnHandle:= findwindowex(rundemo,0,'Button','Run &demo');
if btnHandle<>0 then
begin
pressButtonDown(btnHandle);
result:=true;
end;
end;
end;
function PDFisOpen():boolean;
var readerHandle,mdiHandle,mdiHandle2:Cardinal;
Title: array[0..255] of Char;
begin
readerHandle:= findwindowEx(0,0,'AdobeAcrobat',nil);
result:=false;
if readerHandle<>0 then
begin
mdiHandle:= findwindowex(readerHandle,0,'MDIClient',nil);
if mdiHandle<>0 then
begin
mdiHandle2:= findwindowex(mdiHandle,0,'AcrobatMDIChildWnd',nil);
GetWindowText(mdiHandle2, Title, SizeOf(Title));
// showmessage('AcrobatMDIChildWnd='+string(Title));
if pos('.pdf',ansilowercase(string(Title)))>0 then
result:=true;
end;
end;
end;
function kuoBianAction():boolean;
var readerHandle:Cardinal;
mdiHandle: Cardinal;
mdiHandle2: Cardinal;
trimHandle: Cardinal;
ImpositionHandle: Cardinal;
DownNum: Integer;
NextBtn: Cardinal;
begin
readerHandle:= findwindowEx(0,0,'AdobeAcrobat',nil);
result:=false;
DownNum:=0;
if readerHandle<>0 then
begin
SetForegroundWindow(readerHandle);
// ForceForegroundWindow(readerHandle);
// form1.Memo1.Lines.Add('find AdobeAcrobat');
//Alt+P
keybd_event(18, MapVirtualKey(18, 0), 0, 0);
keybd_event(80, MapVirtualKey(80, 0), 0, 0);
keybd_event(80, MapVirtualKey(80, 0), KEYEVENTF_KEYUP, 0);
keybd_event(18, MapVirtualKey(18, 0), KEYEVENTF_KEYUP, 0);
DownNum:=strtointdef(form1.edtDownNum.Text,1); //工具菜单光标首次下移多少次
while DownNum>0 do
begin
sleep(100);
//方向键down (1次)
keybd_event(VK_DOWN, MapVirtualKey(VK_DOWN, 0), 0, 0);
keybd_event(VK_DOWN, MapVirtualKey(VK_DOWN, 0), KEYEVENTF_KEYUP, 0);
dec(DownNum);
end;
sleep(200);
//方向键 right(1次)
keybd_event(VK_RIGHT, MapVirtualKey(VK_RIGHT, 0), 0, 0);
keybd_event(VK_RIGHT, MapVirtualKey(VK_RIGHT, 0), KEYEVENTF_KEYUP, 0);
sleep(200);
//方向键 up(1次)
keybd_event(VK_UP, MapVirtualKey(VK_UP, 0), 0, 0);
keybd_event(VK_UP, MapVirtualKey(VK_UP, 0), KEYEVENTF_KEYUP, 0);
sleep(200);
//方向键 up(1次)
keybd_event(VK_UP, MapVirtualKey(VK_UP, 0), 0, 0);
keybd_event(VK_UP, MapVirtualKey(VK_UP, 0), KEYEVENTF_KEYUP, 0);
sleep(200);
//方向键 up(1次)
keybd_event(VK_UP, MapVirtualKey(VK_UP, 0), 0, 0);
keybd_event(VK_UP, MapVirtualKey(VK_UP, 0), KEYEVENTF_KEYUP, 0);
sleep(100);
//回车键 Enter (1次)
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);
while not closeAboutWindow() do
begin
sleep(200);
closeAboutWindow();
break;
end;
sleep(500);
trimHandle:=findwindowex(0,0,'#32770','Trim and shift 1 - page selection');
while trimHandle=0 do
begin
application.ProcessMessages ;
trimHandle:=findwindowex(0,0,'#32770','Trim and shift 1 - page selection');
end;
if trimHandle<>0 then
begin
// SetForegroundWindow(trimHandle);
ForceForegroundWindow(trimHandle);
// form1.Memo1.Lines.Add('find Trim and shift 1 - page selection');
sleep(1000);
NextBtn:= findwindowex(trimHandle,0,'Button','&Next');
while NextBtn=0 do
begin
application.ProcessMessages ;
NextBtn:= findwindowex(trimHandle,0,'Button','&Next');
end;
if NextBtn<>0 then
begin
pressButtonDown(NextBtn);
end
else
begin
//回车键 Enter (1次)
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);
end;
NextBtn:=0;
sleep(1000);
//回车键 Enter (1次)
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);
sleep(1000);
//回车键 Enter (1次)
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);
// sleep(300);
while True do
begin
application.ProcessMessages ;
// sleep(100);
ImpositionHandle:=findwindow(nil,'Imposition');
if ImpositionHandle>0 then
begin
break;
end;
end;
while True do
begin
application.ProcessMessages ;
ImpositionHandle:=findwindow(nil,'Imposition');
if ImpositionHandle=0 then
begin
// showmessage('find Imposition window');
//form1.Memo1.Lines.Add('本次扩边完毕!');
//Ctrl+S 保存
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);
keybd_event(83, MapVirtualKey(83, 0), 0, 0);
keybd_event(83, MapVirtualKey(83, 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0);
sleep(3000);
//Ctrl+W 关闭
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);
keybd_event(87, MapVirtualKey(87, 0), 0, 0);
keybd_event(87, MapVirtualKey(87, 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0);
break;
end;
end;
result:=true;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
pdflist,configFile: TStrings;
i: integer;
label ok;
begin
//开始扩边
// Memo1.Clear ;
pdflist:=tstringlist.Create ;
configFile:=tstringlist.Create ;
configFile.Add('pdfpath='+edit1.Text); //PDF所在路径
configFile.Add('acrobat7='+edit2.Text); //Acrobat7完整路径
configFile.Add('DownNum='+trim(edtDownNum.Text));
configFile.SaveToFile(extractfilepath(application.ExeName)+'setinfo.txt');
findfiles(edit1.Text,'*.pdf',pdflist);
try
for i := 0 to pdflist.Count-1 do
begin
application.ProcessMessages ;
shellexecute(handle,'open',pchar(edit2.Text),pchar(pdflist[i]),nil,1);
while True do
begin
application.ProcessMessages ;
if PDFisOpen() then //文件已经打开
begin
ok:
application.ProcessMessages ;
if kuoBianAction() then //扩边
begin
if i=pdflist.Count-1 then
begin
TrayIcon1.BalloonTimeout:=30000;
TrayIcon1.BalloonTitle:='全部扩边完毕';
end;
TrayIcon1.BalloonTitle:='共有 '+inttostr(pdflist.Count)+' 个PDF ';
TrayIcon1.BalloonHint:='已处理:'+inttostr(i+1)+' 个PDF!';
TrayIcon1.ShowBalloonHint;
break;
end
else
goto ok;
end;
end;
self.Caption:='已处理('+inttostr(i+1)+')';
end;
finally
freeandnil(configFile);
freeandnil(pdflist);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var loadCfg:Tstrings;
begin
self.KeyPreview:=false;
edit1.Clear ;
edit2.Clear ;
//edit1.Text:='E:\tools\data';
//edit2.Text:='F:\Program Files\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe';
loadCfg:=tstringlist.Create ;
try
if fileExists(extractfilepath(application.ExeName)+'setinfo.txt') then
begin
loadCfg.LoadFromFile(extractfilepath(application.ExeName)+'setinfo.txt');
edit1.Text:=loadCfg.Values['pdfpath'];
edit2.Text:=loadCfg.Values['acrobat7'];
edtDownNum.Text:=loadCfg.Values['DownNum'];
end;
finally
freeandnil(loadCfg);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var other:Thandle;
begin
{ other:=findwindow('#32770','Trim and shift - advanced options');
if other<>0 then
begin
postmessage(other,wm_close,0,0);
end;
}
end;
end.
delphi模拟按键精灵自动控制PDF页面自动扩边的源代码的更多相关文章
- 【按键精灵篇】如何做一个自动打开APP进入注册页面自动输入自己手机号
按键精灵,虽然很早听过,但是一直没有真正使用过,所以最近有点时间也简单试一下,通过脚本自动清理APP缓存,打开百家号并自动进入注册页面输入自己的手机号. 软件清单 1. 雷电手机模拟器:https:/ ...
- 转:Android随笔之——使用Root权限实现后台模拟全局按键、触屏事件方法(类似按键精灵)
本文转载自CSDN的jzj1993,原文连接:http://blog.csdn.net/jzj1993/article/details/39158865 有时我们需要使用安卓实现在后台模拟系统按键,比 ...
- delphi 向其他程序发送模拟按键
向其他程序发送模拟按键: 1.用keybd_event: varh : THandle;beginh := FindWindow('TFitForm', '1stOpt - [Untitled1]') ...
- 【笨嘴拙舌WINDOWS】实践检验之按键精灵【Delphi】
通过记录键盘和鼠标位置和输入信息,然后模拟发送,就能够创建一个按键精灵! 主要代码如下: library KeyBoardHook; { Important note about DLL memory ...
- 将HTML页面自动保存为PDF文件并上传的两种方式(一)-前端(react)方式
一.业务场景 公司的样本检测报告以React页面的形式生成,已调整为A4大小的样式并已实现分页,业务上需要将这个网页生成PDF文件,并上传到服务器,后续会将这个文件发送给客户(这里不考虑). 二.原来 ...
- 安卓使用Root权限实现后台模拟全局按键、触屏事件方法(类似按键精灵)
继续在网上搜索安卓按键模拟(其实那时都不知道用什么关键字好了,能想到的关键字都用遍了,但是搜索出来的结果,都是之前提到的那几个依赖源码环境和系统权限的方案).发现有很多介绍ADB调试,向手机发送按键事 ...
- GitHub Java项目推荐|不需要 ROOT权限的类似按键精灵的自动操作
不需要 ROOT 权限的类似按键精灵的自动操作软件,可以实现自动点击.滑动.输入文字.打开应用等.Auto.js 的大部分用户用它来点赞.签到.刷游戏 项目分析 仓库名称:Auto.js 标星(sta ...
- Delphi驱动方式WINIO模拟按键 可用
http://www.delphitop.com/html/yingjian/152.html Delphi驱动方式WINIO模拟按键 作者:admin 来源:未知 日期:2010/2/1 1:14: ...
- 按键精灵如何调用Excel及按键精灵写入Excel数据的方法教程---入门自动操作表格
首先来建立一个新的Excel文档,在桌面上点击右键,选择[新建]-[Excel工作表],命名为[新手学员]. 现在这个新Excel文档是空白的,我们接下来会通过按键精灵的脚本来打开并写入一些数据.打开 ...
随机推荐
- Smart210学习记录-----Linux i2c驱动
一:Linux i2c子系统简介: 1.Linux 的 I2C 体系结构分为 3 个组成部分: (1) I2C 核心. I2C 核心提供了 I2C 总线驱动和设备驱动的注册.注销方法,I2C 通信方法 ...
- [Android自定义控件] Android自定义控件
转载自:http://blog.163.com/ppy2790@126/blog/static/103242241201382210910473/ 开发自定义控件的步骤: 1.了解View的工作原理 ...
- linux权限管理_文件特殊权限
一.SetUID功能 设定SetUID的方法 4代表SUID s代表SUID权限 S代表报错了,原因没有执行权限 # chmod 4755 文件名(最好用这种方法) # chmod u+s 文件名 取 ...
- 【转载】MATLB绘图
原文地址:http://www.cnblogs.com/hxsyl/archive/2012/10/10/2718380.html 作为一个功能强大的工具软件,Matlab具有很强的图形处理功能,提供 ...
- 存储OS
openfiler这个登陆慢 是https协议的问题 http://www.getnas.com/open-source-nas FreeNAS®,目前最受欢迎的开源免费 NAS 操作系统之一,基于以 ...
- .Net操作Excel
先去官网:http://npoi.codeplex.com/下载需要引入dll(可以选择.net2.0或者.net4.0的dll),然后在网站中添加引用. .Net导出代码: /// <summ ...
- HTML5外包团队-技术分享【使用HTML5的VIDEO标记播放RTSP视频流】
使用HTML5的VIDEO播放RTSP实时视频流源代码: <!DOCTYPE html> <html><head> <meta http-equiv=&quo ...
- Token验证失败
Token验证失败 微信 微信公众平台开发 Token校验失败 URL Token原文 http://www.cnblogs.com/txw1958/p/token-verify.html Token ...
- Git+Github代码管理控制
关于Git的发展历程这里就不多介绍了,有兴趣的话可以查阅一下Git的相关历程. 如果你在做的项目或者自己写的一些项目由于需要用的分布式.或者团队开发.再或者你不善于对代码进行定期备份,但又希望自己的代 ...
- Java事务处理全解析(五)—— Template模式
在本系列的上一篇文章中,我们讲到了使用TransactionManger和ConnectionHolder完成线程安全的事务管理,在本篇中,我们将在此基础上引入Template模式进行事务管理. Te ...