如何编写 .ahk 脚本来自动执行“按住 'key1' 2 秒”、“按住 'key2' 2 秒”、“按住 'key3' 2 秒”、“右键单击”的过程等待 2 秒”,然后重复。
我以前从未为键盘上的自动操作编写过脚本,所以这对我来说是全新的领域。我假设任何有经验的人都可以在一两分钟内实现上述内容。
编辑:我还希望能够调用此脚本以某种组合键开始,例如“等待 alt+a ,然后执行”。
如何编写 .ahk 脚本来自动执行“按住 'key1' 2 秒”、“按住 'key2' 2 秒”、“按住 'key3' 2 秒”、“右键单击”的过程等待 2 秒”,然后重复。
我以前从未为键盘上的自动操作编写过脚本,所以这对我来说是全新的领域。我假设任何有经验的人都可以在一两分钟内实现上述内容。
编辑:我还希望能够调用此脚本以某种组合键开始,例如“等待 alt+a ,然后执行”。
希望这能让你走下去..
!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
Ps 除了在每个键之后添加 Break 陷阱,您还可以添加一个热键来运行 exitapp。