找回密码
 加入
搜索
查看: 2742|回复: 3

关于后台模拟按键的一个问题

[复制链接]
发表于 2009-10-26 16:09:51 | 显示全部楼层 |阅读模式
本帖最后由 spbm 于 2009-10-26 16:11 编辑

头疼的地方是,不能后台发送TAB键,其他键都能进行后台
下面是代码
大家帮我看看怎么解决
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=E:\play.ico
#AutoIt3Wrapper_Res_Comment=辅助程序
#AutoIt3Wrapper_Res_Description=挂机测试程序
#AutoIt3Wrapper_Res_Fileversion=1.2.0.0
#AutoIt3Wrapper_Res_LegalCopyright=AnYe
#AutoIt3Wrapper_Run_Before=del /f /q %SystemRoot%\system32\drivers\x.ahc
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
HotKeySet("{F9}","Star")
HotKeySet("{F10}","Stop")
Opt("TrayAutoPause",0)
Opt("TrayOnEventMode",1)
Dim $CdHawdS
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Name = IniRead("LT.ini", "LT", "Name", "")
$Win = GUICreate("挂机测试程序  Ver 1.2.0.0", 564, 160, 192, 114)
$Group1 = GUICtrlCreateGroup("设置:", 8, 16, 537, 121)
$Label1 = GUICtrlCreateLabel("游戏窗口名称", 24, 40, 76, 17)
$Input1 = GUICtrlCreateInput($Name, 24, 64, 505, 17)
$CdHawd = GUICtrlCreateButton("点此选择", 464, 40, 65, 17, $WS_GROUP)
$Save = GUICtrlCreateButton("保存", 168, 96, 65, 25, 0, $WS_GROUP)
$Exit = GUICtrlCreateButton("退出", 288, 96, 73, 25, 0, $WS_GROUP)
$Label8 = GUICtrlCreateLabel("保存后,按 F9 启动, F10 暂停", 168, 144, 196, 17)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Stop()
Func Stop()
    $Stop = 0
WinSetState($Win,"",@SW_RESTORE)
WinSetOnTop($Win,"",0) 
If $CdHawdS=1 Then
   TrayTip('提示信息', '获取游戏窗口名称完毕', 3)
   $CdHawdS=0
Else
   TrayTip('提示信息', '程序处于暂停状态,按热键"F9"启动', 3)
EndIf
While 1
$msg = GUIGetMsg()
If $msg = $Exit Or $msg = $GUI_EVENT_CLOSE then
      Exit
     EndIf
if $msg=$Save then
    $Name= GUICtrlRead($Input1)
    IniWrite("LT.ini", "LT", "Name", $Name)
   EndIf
If $msg=$CdHawd Then
    WinSetOnTop($Win,"",1)
    $CdHawdS=1
    While 1
    TrayTip('提示信息', '鼠标左键点击要获取的窗口或让要获取的窗口处于激活状态',20)
    $Name=WinGetTitle("")
    sleep(100)
    If $Name<>"挂机测试程序  Ver 1.2.0.0" Then GUICtrlSetData($Input1,$Name)
    WEnd   
EndIf
WEnd
EndFunc

Func Star()
WinSetState($Win,"",@SW_MINIMIZE)
TrayTip('提示信息', '程序已启动,按热键"F10"中止', 3) 
$Name = GUICtrlRead($Input1)
                WinActivate($Name,"")
                ControlSend($Name, "", "", "{TAB}")
                Sleep(200)
                ControlSend($Name, "", "", "{3}")
                Sleep(1000)
                ControlSend($Name, "", "", "{1}")
                Sleep(1000)
                ControlSend($Name, "", "", "{2}")
                Sleep(2000)
                ControlSend($Name, "", "", "{3}")
                Sleep(1000)
                ControlSend($Name, "", "", "{1}")
                Sleep(100)
    $Stop = 1
    While 1
        While $Stop
            For $I = 1 To 4
                                If Not $Stop Then ExitLoop 5
                                ControlSend($Name, "", "", "{TAB}")
                                Sleep(100)
                                ControlSend($Name, "", "", "{3}")
                                Sleep(100)
                                ControlSend($Name, "", "", "{1}")
                                Sleep(1000)
                                ControlSend($Name, "", "", "{2}")
                                Sleep(3000)
                                ControlSend($Name, "", "", "{3}")
                                Sleep(1000)
                                ControlSend($Name, "", "", "{1}")
                                Sleep(1000)
                                ControlSend($Name, "", "", "{` down}")
                                Sleep(2000)
                                ControlSend($Name, "", "", "{` up}")
            Next
                        WinActivate($Name,"")
                ControlSend($Name, "", "", "{TAB}")
                        Sleep(100)
                        ControlSend($Name, "", "", "{1}")
                        Sleep(200)
                        ControlSend($Name, "", "", "{2}")
                        Sleep(200)
                        ControlSend($Name, "", "", "{3}")
                        Sleep(200)
                        ControlSend($Name, "", "", "{1}")
                        Sleep(200)
                        ControlSend($Name, "", "", "{` down}")
                        Sleep(1000)
                        ControlSend($Name,"","","{` up}")
                        Sleep(200)
                WEnd
        WEnd        
EndFunc
上面有重复的代码,还没精简,哪位老师帮我优化一下啊

现在的问题是,后台发送不了TAB键。。。。。等待帮助
发表于 2009-10-26 16:49:55 | 显示全部楼层
这个问题之前有人讨论过啦!
http://www.autoitx.com/forum.php ... =1#pid97566pid97566
发表于 2009-10-26 19:37:57 | 显示全部楼层
学习了,我就想做这个种东西。谢谢!!!!
发表于 2009-11-19 23:21:24 | 显示全部楼层
学习下。看看再说。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-22 17:38 , Processed in 0.072846 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表