找回密码
 加入
搜索
查看: 1984|回复: 2

[AU3基础] 请精简该代码

[复制链接]
发表于 2010-7-29 16:00:47 | 显示全部楼层 |阅读模式
本帖最后由 Evol 于 2010-7-29 17:01 编辑

本人昨天写的一个用来当多次剪贴板的代码。但是总感觉数组那里调用及函数那里重复很多,但我写循环用来将数组变量重新赋值时,会提示错误。想请大侠们帮我精简一下代码,让我深入学习一下AUTOIT中数组及函数的使用方法。
Opt("TrayAutoPause",0)
HotKeySet("^{F4}", "Endme")
HotKeySet("{Pause}", "Clearme")
HotKeySet("^1", "Show1")  ;Alt-1
HotKeySet("^2", "Show2")  ;Alt-1
HotKeySet("^3", "Show3")  ;Alt-1
HotKeySet("^4", "Show4")  ;Alt-1
HotKeySet("^5", "Show5")  ;Alt-1
HotKeySet("^6", "Show6")  ;Alt-1
HotKeySet("^7", "Show7")  ;Alt-1
HotKeySet("^8", "Show8")  ;Alt-1
HotKeySet("^9", "Show9")  ;Alt-1
HotKeySet("^0", "Show10")  ;Alt-1
HotKeySet("^!1", "Puts1")  ;Alt-1
HotKeySet("^!2", "Puts2")  ;Alt-1
HotKeySet("^!3", "Puts3")  ;Alt-1
HotKeySet("^!4", "Puts4")  ;Alt-1
HotKeySet("^!5", "Puts5")  ;Alt-1
HotKeySet("^!6", "Puts6")  ;Alt-1
HotKeySet("^!7", "Puts7")  ;Alt-1
HotKeySet("^!8", "Puts8")  ;Alt-1
HotKeySet("^!9", "Puts9")  ;Alt-1
HotKeySet("^!0", "Puts10")  ;Alt-1
HotKeySet("^!c", "Bord")  ;Alt-1
HotKeySet("^`", "ISSHow")  ;Alt-1
Global $A[10]=["","","","","","","","","",""]
Global $F=0,$msg,$K=-1,$S=0
Do
        Sleep(500)
        $msg="Ctrl+1 = " & $A[0] & @CRLF & "Ctrl+2 = " & $A[1] & @CRLF & "Ctrl+3 = " & $A[2] & @CRLF & "Ctrl+4 = " & $A[3] & @CRLF & "Ctrl+5 = " & $A[4] & @CRLF & "Ctrl+6 = " & $A[5] & @CRLF & "Ctrl+7 = " & $A[6] & @CRLF & "Ctrl+8 = " & $A[7] & @CRLF & "Ctrl+9 = " & $A[8] & @CRLF & "Ctrl+0 = " & $A[9]
        If $S=1 Then
                ToolTip($msg,0,@DesktopHeight-230,"Evol's Program , Ctrl+F4 to Exit.",0,1)
        Else
                ToolTip("")
        EndIf
Until $F=1
Func ISShow()
    If $S=1 Then
                $S=0
        Else
                $S=1
        EndIf
EndFunc
Func Bord()
        Send("^c")
        $K=$K+1
        $A[$K]=ClipGet()
        If $K=9 Then
                MsgBox(16,"提示","系统剪贴板已存储满。将从第一项开始重新循环保存。")
                $K=-1
        EndIf
EndFunc
Func Clearme()
        For $U=0 To 9
                $A[$U]=""
        Next
EndFunc
Func Show1()
    ClipPut($A[0])
        Send("^v")
EndFunc
Func Show2()
    ClipPut($A[1])
        Send("^v")
EndFunc
Func Show3()
    ClipPut($A[2])
        Send("^v")
EndFunc
Func Show4()
    ClipPut($A[3])
        Send("^v")
EndFunc
Func Show5()
    ClipPut($A[4])
        Send("^v")
EndFunc
Func Show6()
    ClipPut($A[5])
        Send("^v")
EndFunc
Func Show7()
    ClipPut($A[6])
        Send("^v")
EndFunc
Func Show8()
    ClipPut($A[7])
        Send("^v")
EndFunc
Func Show9()
    ClipPut($A[8])
        Send("^v")
EndFunc
Func Show10()
    ClipPut($A[9])
        Send("^v")
EndFunc
Func Puts1()
        Send("^C")
    $A[0]=ClipGet()
EndFunc
Func Puts2()
        Send("^C")
    $A[1]=ClipGet()
EndFunc
Func Puts3()
        Send("^C")
    $A[2]=ClipGet()
EndFunc
Func Puts4()
        Send("^C")
    $A[3]=ClipGet()
EndFunc
Func Puts5()
        Send("^C")
    $A[4]=ClipGet()
EndFunc
Func Puts6()
        Send("^C")
    $A[5]=ClipGet()
EndFunc
Func Puts7()
        Send("^C")
    $A[6]=ClipGet()
EndFunc
Func Puts8()
        Send("^C")
    $A[7]=ClipGet()
EndFunc
Func Puts9()
        Send("^C")
    $A[8]=ClipGet()
EndFunc
Func Puts10()
        Send("^C")
    $A[9]=ClipGet()
EndFunc
Func Endme()
    $F=1
EndFunc
发表于 2010-7-29 16:26:17 | 显示全部楼层
首先楼主提问的标题有问题。

其次是你的代码 Show n ()   Puts n ()  这些自定义函数几乎都是在做相同的事,可以定义参数来完成,这样应该会简单很多的。
 楼主| 发表于 2010-7-29 16:57:05 | 显示全部楼层
不知道你有没有看过帮助,键盘控制管理——HotKeySet里,
要调用一个函数 不能 给函数加上参数. 它将会被忽略.
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-22 01:37 , Processed in 0.075554 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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