automation - Inno Setup 可以发送按键和鼠标按下吗?如果没有,如何使用安装程序来完成此操作?

标签 automation inno-setup autohotkey nsis

我是 [Microsoft Windows] 安装程序和 Inno Setup 的新手但我需要知道是否可以使用 Inno Setup(或等效工具)在安装过程中自动输入基于 GUI 的 Windows 程序,例如例如,通过单击菜单并选择子项目?

我知道AutoItAutoHotkey ,以及NSIS ,但是强烈推荐 Inno Setup 作为软件包/安装程序,而且我也喜欢学习一点 Pascal 编程的想法,这是值得的;)

欢迎任何想法或想法:-)

最佳答案

我同意@Deanna,SendInput函数是模拟用户输入的最佳选择。在下面的脚本中,我展示了如何在绝对屏幕位置(以像素为单位)上模拟鼠标单击。作为一个例子,我试图通过帮助/关于 Inno Setup 菜单项显示 Inno Setup 的“关于”框(如果您的屏幕设置与我相同,并且 Inno Setup IDE 最大化,则可能会出现这样的情况)甚至点击该菜单项。所以这只是鼠标部分(并且您只能获得有限的功能)。将其作为证据,可以从 Inno Setup 模拟用户输入:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
OutputDir=userdocs:Inno Setup Examples Output

[code]
const
  SM_CXSCREEN = 0;
  SM_CYSCREEN = 1;
  INPUT_MOUSE = 0;
  MOUSEEVENTF_MOVE = $0001;
  MOUSEEVENTF_LEFTDOWN = $0002;
  MOUSEEVENTF_LEFTUP = $0004;
  MOUSEEVENTF_RIGHTDOWN = $0008;
  MOUSEEVENTF_RIGHTUP = $0010;
  MOUSEEVENTF_MIDDLEDOWN = $0020;
  MOUSEEVENTF_MIDDLEUP = $0040;
  MOUSEEVENTF_VIRTUALDESK = $4000;
  MOUSEEVENTF_ABSOLUTE = $8000;
type
  TMouseInput = record
    Itype: DWORD;    
    dx: Longint;
    dy: Longint;
    mouseData: DWORD;
    dwFlags: DWORD;
    time: DWORD;
    dwExtraInfo: DWORD;
  end;

function GetSystemMetrics(nIndex: Integer): Integer;
  external '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c384a6b790bab0b7a6ae8ea6b7b1aaa0b083b6b0a6b1f0f1eda7afaf" rel="noreferrer noopener nofollow">[email protected]</a> stdcall';
function SendMouseInput(nInputs: UINT; pInputs: TMouseInput;
  cbSize: Integer): UINT; 
  external '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ac9fff4fed3f4eaefeedaefe9ffe8a9a8b4fef6f6" rel="noreferrer noopener nofollow">[email protected]</a> stdcall';

function SendMouseClick(Button: TMouseButton; X, Y: Integer): Boolean;
var
  Flags: DWORD;
  Input: TMouseInput;
  ScreenWidth: Integer;
  ScreenHeight: Integer;
begin
  Result := False;
  Flags := MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_VIRTUALDESK or MOUSEEVENTF_MOVE;
  ScreenWidth := GetSystemMetrics(SM_CXSCREEN);
  ScreenHeight := GetSystemMetrics(SM_CYSCREEN);

  Input.Itype := INPUT_MOUSE;
  Input.dx := Round((X * 65536) / ScreenWidth);
  Input.dy := Round((Y * 65536) / ScreenHeight);
  case Button of
    mbLeft: Input.dwFlags := Flags or MOUSEEVENTF_LEFTDOWN;
    mbRight: Input.dwFlags := Flags or MOUSEEVENTF_RIGHTDOWN;
    mbMiddle: Input.dwFlags := Flags or MOUSEEVENTF_MIDDLEDOWN;
  end;  
  Result := SendMouseInput(1, Input, SizeOf(Input)) = 1;

  if Result then
  begin
    Input.Itype := INPUT_MOUSE;
    Input.dx := Round((X * 65536) / ScreenWidth);
    Input.dy := Round((Y * 65536) / ScreenHeight);
    case Button of
      mbLeft: Input.dwFlags := Flags or MOUSEEVENTF_LEFTUP;
      mbRight: Input.dwFlags := Flags or MOUSEEVENTF_RIGHTUP;
      mbMiddle: Input.dwFlags := Flags or MOUSEEVENTF_MIDDLEUP;
    end;    
    Result := SendMouseInput(1, Input, SizeOf(Input)) = 1;
  end;
end;

procedure InitializeWizard;
begin
  if MsgBox('Are you sure you want to let the installer click ' +
    'somewhere on your screen ? TLama warned you :-)', mbConfirmation, 
    MB_YESNO) = IDYES then
  begin
    if not SendMouseClick(mbLeft, 242, 31) then 
      MsgBox(SysErrorMessage(DLLGetLastError), mbError, mb_Ok);
    if not SendMouseClick(mbLeft, 382, 263) then 
      MsgBox(SysErrorMessage(DLLGetLastError), mbError, mb_Ok);
  end;
end;

关于automation - Inno Setup 可以发送按键和鼠标按下吗?如果没有,如何使用安装程序来完成此操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14741933/

相关文章:

combobox - autohotkey Control仅获取选定的组合框值

autohotkey - 如何将 AutoHotKey 代码设置为仅在 chrome 中运行?

php - 检查联系表是否有效(自动测试)

api - 如何在 Karate 特征文件中传递体型?

java - Inno Setup 常量相当于 System.getProperty ("user.home")

sharepoint - 如何使用 Sharepoint 服务器作为 Inno Setup 文件的源?

inno-setup - Inno Setup 可以检测到可以模拟 x64 的 ARM64 硬件上的 Windows11 吗?

autohotkey - 向上/向下键在 Onenote 2016 中对于 Autohotkey 不起作用

internet-explorer - VBA IE自动化-阅读iFrame

python - mechanize: cookies 混淆了?