AutoHotKey脚本用于简单的功能

时间:2013-01-18 07:41:33

标签: scripting autohotkey

如何编写.ahk脚本来自动执行此过程 “按住'key1'2秒”, “按住'key2'2秒”, “按住'key3'2秒”, “右键单击,等待2秒钟”,然后重复。

我从来没有为键盘上的自动操作编写脚本,所以这对我来说都是新的领域。我认为任何有经验的人都可以在一两分钟内实现上述目标。

编辑:我还希望能够通过某种键组合来调用此脚本,例如“等待alt + a,然后执行”。

1 个答案:

答案 0 :(得分:1)

希望这能让你好起来......

!a:: ; Alt+a to start script
Loop 
{ ; Start of loop
    GetKeyState, keystate, Pause, P ; Get the state of the Pause key
    if keystate = D  ; The Pause key was held down, break out of the loop.
        break ; Stop loop when the Pause key was held down
    Send, {Space Down} ; This will NOT autorepeat
    Sleep 2000 ; Wait 200 ms
    Send, {Space Up} ; Release the key
    GetKeyState, keystate, Pause, P ; Get the state of the Pause key
    if keystate = D  ; The Pause key was held down, break out of the loop.
        break ; Stop loop when the Pause key was held down
    Send, {b Down} ; This will NOT autorepeat
    Sleep 2000 ; Wait 200 ms
    Send, {b Up} ; Release the key
    GetKeyState, keystate, Pause, P ; Get the state of the Pause key
    if keystate = D  ; The Pause key was held down, break out of the loop.
        break ; Stop loop when the Pause key was held down
    MouseClick, left, 150,150 ; Click the mouse at 150X,150Y pixels, check exact mouse coordinates with AHK Window Spy
} ; End of loop
return ; End of script

P.S。除了在每个键之后添加Break陷阱,您还可以添加一个热键来运行exitapp。