Autohotkey Win XP自动执行小任务

时间:2011-11-08 08:49:09

标签: automation windows-xp autohotkey

我有一个小任务我想使用Autohotkey进行自动化,看起来它或多或少可以直接转换为autohotkey语法:

1. Ctrl+v
2. Alt+tab
3. Click certain link in a window (no combo-key for this but it's always in the same place)
4. Enter (carriage return)
5. Alt+s
6. Ctrl+v
7. Enter

现在将这个组合映射到其他内容会很不错,例如Windows Key + Space。

到目前为止我得到的是:

0. SetWinDelay 100  (using a connection to an remote computer)
0. SetKeyDelay 0
1. Send, ^c
1. ClipWait, 0.1 
2. Send, {Alt down}{tab}
2. Send, {Alt up}
3. ?????
4. Send, {enter}
5. Send, !s
6. Send, ^v
7. Send, {enter}

这大概是对的吗?任何人都可以帮我修理或填补空洞,可以这么说:)

步骤3,4和6的另一个替代方法是简单地循环剪贴板的内容(数字字符串)并将字符串的每个字母发送到按键?也许这将是更容易的方式

1 个答案:

答案 0 :(得分:1)

如果您想要“点击”某个位置,要打开菜单,您可以先右键单击AutoHotKey图标并打开“窗口间谍”。此窗口间谍将显示鼠标位置。 Yo可以使用鼠标位置在活动应用程序中执行操作。

示例:

SoundBeep 1000, 300 ; Wake up user

SplashTextOn, 200, 100, Script Preparations, Please Click on the person icon link. ; Show new Instructions text

WinMove, Script Preparations,, (A_ScreenWidth/2)+150, (A_ScreenHeight/2)+200 ; Move the window with the name "Script Preparations" Down and Right on the main screen

KeyWait, LButton, D ; Wait for LeftMouseButton click Down

MouseGetPos, xposE ,yposE ; Store the position where the mouse was clicked (Employee)

MouseClick, left, %xposE% ,%yposE%, 2 ; Perform a double mouse click on the captured mouse location

SplashTextOff ; Remove Text box

在这种情况下,我首先要求用户手动点击正确的位置。仅当要单击的位置在活动窗口中更改(活动窗口中的可变切片)时,才需要这样做。存储位置后,您可以在整个脚本中重复使用它。

b.t.w。而不是使用 Alt + Tab ,我建议使用这个:

settitlematchmode, 1 ; Set search in title to start with....

settitlematchmode, Fast ; Slow is not required here. Slow is only required when hidden text needs to be found.

SwitchWindow("Microsoft Excel - 1 QRM Upload and Change Template") ; Activate the 
window with the title: Microsoft Excel - 1 QRM Upload and Change Template

You could even use someting like this:

SetTitleMatchMode, 2 ; Ensure that the Title Match mode is set to 2: Find anywhere in the title

  SetTitleMatchMode, Fast ; Ensure that the Title Match mode is set to FAST

  winactivate, %WindowName% ; Activate the window with the title stored in the variable WindowName

  WinWaitActive, %WindowName%, , 5 ; Wait up to five seconds for the screen

  if ErrorLevel ; Execute this when the window is not activated within 5 seconds

  { ; Start-If Wait failed

    SoundBeep 1000 , 1000 ; Warn the user

    MsgBox,4097,Time Out, Script timed out while waiting for %WindowName%.`n`rYou Must manually activate %WindowName% and then continue the script by pressing OK. ; Message to user

    IfMsgBox, Cancel ; Do when the user clicked on Cancel

    { ; Start-If User clicked Cancel

      ExitApp ; Exit this program when the user clicked on Cancel

    } ; End-If User clicked Cancel

    WinWaitActive, %WindowName%, , 5 ; Try to activate the window AGAIN

    if ErrorLevel ; If window can't be found

    { ; Start-If window can't be found

      MsgBox,4096,Exit, %WindowName% still NOT Active. ; Warn user

      ExitApp ; Exit this program when the expected window is still not found

    } ; End-If window can't be found

  } ; End-If Wait failed

此致

罗伯特·伊尔布林克