【已解决】关于循环停止的疑问...
本帖最后由 alomoi 于 2011-9-1 10:26 编辑按道理说按下热键 insert 后,鼠标点击的循环就会停止。
但是不知道为什么,第一次按下热键程序稍后还会自动恢复到循环中,要连续按两次才有效。
不知道其原因所在,求赐教m(_ _)m
以下为源码:#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#NoTrayIcon
$Form1 = GUICreate("鼠标连点器", 280, 115, 645, 352)
$Button1 = GUICtrlCreateButton("开始", 176, 32, 75, 25)
$Input1 = GUICtrlCreateInput("1000", 24, 32, 121, 21)
$Label1 = GUICtrlCreateLabel("[等待]", 232, 88, 36, 17)
GUISetState(@SW_SHOW)
HotKeySet("{insert}","end1")
HotKeySet("{esc}","quit")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button1
$1 = True
GUICtrlSetData($Label1,"[运行]")
While $1 = True
MouseClick("left")
Sleep(GUICtrlRead($Input1))
wend
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func quit()
Exit
EndFunc
Func end1()
$1 = False
GUICtrlSetData($Label1,"[停止]")
EndFunc 关注中,期待答案 参考 3mile 的答案:#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $Flg = True
Local $t = 0
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 318, 120, 468, 171)
$Button1 = GUICtrlCreateButton("开始循环", 48, 60, 80, 40)
;$Button2 = GUICtrlCreateButton("结束循环", 208, 60, 80, 40)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
$msg=GUIGetMsg()
Switch $msg
case -3
Exit
Case $Button1
if GUICtrlRead($Button1)="开始循环" and $Flg=True Then
GUICtrlSetData($Button1,"结束循环")
TEST()
Else
GUICtrlSetData($Button1,"开始循环")
EndIf
EndSwitch
WEnd
Func TEST()
While $Flg
ToolTip($t)
$t+=1
WEnd
$Flg=True
$t=0
EndFunc
Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
#forceref $hWnd, $Msg
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0x0000FFFF)
Local $hCtrl = $lParam
Switch $hCtrl
Case GUICtrlGetHandle($Button1)
if GUICtrlRead($Button1)="结束循环" then
$Flg=False
Else
$Flg=True
EndIf
EndSwitch
EndFunc ;==>WM_COMMAND 3楼贴的代码之前查到过,其中停止循环部分的前半段不明白是何用意...
实际上目前自己也找到了其他解决方法
但是依然想知道1楼中的代码究竟是出于什么原因停止后会自动恢复循环...
求高人赐教m(_ _)m 回复 1# alomoi
我测试后明白了.
问题在鼠标的位置.
先看看循环代码是怎么写的.
MouseClick("left")
Sleep(GUICtrlRead($Input1))
因为你按了开始按钮后鼠标还在开始按钮上.
代码还在循环中,,,所以自动按了开始按钮.
如果按5次开始按钮,就得按5次insert键才能停止.
你试一下按开始按钮后马上把鼠标移动其他地方.
然后按insert键,可以按一次就会停止. 本帖最后由 lixiaolong 于 2011-8-31 16:39 编辑
回复 1# alomoi
这是一个解决方案.
**** Hidden Message ***** 回复alomoi
这是一个解决方案.
**** 本内容被作者隐藏 ****
lixiaolong 发表于 2011-8-31 16:35 http://www.autoitx.com/images/common/back.gif
m(_ _)m,感谢指导。
还真没考虑到这个问题.... 正在研究这个问题 正在研究这个问题 m(_ _)mm(_ _)m 什么物件回复看看。 谢谢分享,收藏了 受教,学习中
页:
[1]