按键精灵,如何设置同一个按键为开始执行脚本和终止执行脚本按键???

按键精灵,如何设置同一个按键为开始执行脚本和终止执行脚本按键???复制粘贴勿进,最好有代码。
比如说,我希望按一下 F9 ,就能让软件先按一下1键,然后不断按2键,再按一下F9,就停止按键。第三次按一下F9,则再执行一次按1键,然后无限次按2键的操作。这样能实现吗?

有一个命令叫多线程 启动 线程ID=BeginThread(线程名) 停止 StopThread(线程ID)
按下F9之后先启动多线程,按122222然后再用 f9 = WaitKey() 读取用户按键,最后再判断是否是F9,用StopThread停用线程ID就好了
大概的代码就是这样
While 1=1
f9 = WaitKey()//先判断,如果是就启动,这个要加循环判断
If f9 = "120" Then
线程ID=BeginThread(脚本)
f9 = WaitKey()//再判断,如果是就停用 这个要加循环判断
If f9 = "120" Then
StopThread 线程ID
End If
End If
Wend
Sub 脚本
游戏12222222脚本
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-05-18

你这个功能能实现,但是不是用热键的方法实现。要在代码里面实现,热键不要用F9,用其他的即可,先启动脚本。代码如下:

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Dim ID
ID = 0
While True
If GetAsyncKeyState(120) < 0 Then 
While GetAsyncKeyState(120) < 0
Delay 50
Wend

If ID = 0 Then 
ID = BeginThread(MyFunction)
Else 
StopThread ID
ID = 0
End If
End If
Delay 50
Wend

Sub MyFunction
KeyPress 49, 1
While True
KeyPress 50, 1
Wend
End Sub

本回答被网友采纳
相似回答