[已解决]这个脚本可以精简代码吗,还有怎么保存配置文件.ini以及怎样避免重复设置热键
本帖最后由 3131210 于 2017-5-23 15:30 编辑这个脚本可以精简代码吗,还有怎么保存配置文件.ini以及运行程序的时候,自动载入配置
还有就是 热键如果使用了,能不能使其他的下拉组合框中,看不到这个热键呢?以免重复设置相同热键#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Dim $var, $ime, $imee = "", $keylist = "Alt + 0|Alt + 1|Alt + 2|Alt + 3|Alt + 4|Alt + 5|Alt + 6|Alt + 7|Alt + 8|Alt + 9"
#Region ### START Koda GUI section ### Form=e:\bak\system\!desktop\form1.kxf
$Form1 = GUICreate("LP快捷辅助", 456, 437, 233, 139)
$Label1 = GUICtrlCreateLabel("英文输入法", 8, 10, 64, 17)
$Label2 = GUICtrlCreateLabel("中文输入法", 8, 42, 64, 17)
$Language1 = GUICtrlCreateCombo("None", 73, 6, 297, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
$Language2 = GUICtrlCreateCombo("None", 73, 38, 297, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
$Save = GUICtrlCreateButton("保存配置", 376, 8, 73, 49)
$Label3 = GUICtrlCreateLabel("快捷", 32, 72, 28, 17)
$Label4 = GUICtrlCreateLabel("热键", 100, 72, 28, 17)
$Label5 = GUICtrlCreateLabel("自定义快捷", 185, 72, 60, 17)
$Label6 = GUICtrlCreateLabel("%s 为剪贴板内容", 300, 72, 90, 17)
$Altbox0 = GUICtrlCreateCheckbox("A → 0", 10, 96, 52, 17)
GUICtrlSetState(-1, 1)
$Altbox1 = GUICtrlCreateCheckbox("A → 1", 10, 120, 52, 17)
$Altbox2 = GUICtrlCreateCheckbox("A → 2", 10, 144, 52, 17)
GUICtrlSetState(-1, 1)
$Altbox3 = GUICtrlCreateCheckbox("A → 3", 10, 168, 52, 17)
GUICtrlSetState(-1, 1)
$Altbox4 = GUICtrlCreateCheckbox("A → 4", 10, 192, 52, 17)
$Altbox5 = GUICtrlCreateCheckbox("A → 5", 10, 216, 52, 17)
$Altbox6 = GUICtrlCreateCheckbox("A → 6", 10, 240, 52, 17)
$Altbox7 = GUICtrlCreateCheckbox("A → 7", 10, 264, 52, 17)
$Altbox8 = GUICtrlCreateCheckbox("A → 8", 10, 288, 52, 17)
$Altbox9 = GUICtrlCreateCheckbox("A → 9", 10, 312, 52, 17)
$Altbo0 = GUICtrlCreateCombo("None", 75, 93, 70, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
$Altbo1 = GUICtrlCreateCombo("None", 75, 117, 70, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
$Altbo2 = GUICtrlCreateCombo("None", 75, 141, 70, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
$Altbo3 = GUICtrlCreateCombo("None", 75, 165, 70, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
$Altbo4 = GUICtrlCreateCombo("None", 75, 189, 70, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
$Altbo5 = GUICtrlCreateCombo("None", 75, 213, 70, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
$Altbo6 = GUICtrlCreateCombo("None", 75, 237, 70, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
$Altbo7 = GUICtrlCreateCombo("None", 75, 261, 70, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
$Altbo8 = GUICtrlCreateCombo("None", 75, 285, 70, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
$Altbo9 = GUICtrlCreateCombo("None", 75, 309, 70, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE))
$Ctrlbox0 = GUICtrlCreateCheckbox("Ctrl + 0", 180, 96, 70, 17)
$Ctrlbox1 = GUICtrlCreateCheckbox("Ctrl + 1", 180, 120, 70, 17)
GUICtrlSetState(-1, 1)
$Ctrlbox2 = GUICtrlCreateCheckbox("Ctrl + 2", 180, 144, 70, 17)
$Ctrlbox3 = GUICtrlCreateCheckbox("Ctrl + 3", 180, 168, 70, 17)
$Ctrlbox4 = GUICtrlCreateCheckbox("Ctrl + 4", 180, 192, 70, 17)
$Ctrlbox5 = GUICtrlCreateCheckbox("Ctrl + 5", 180, 216, 70, 17)
$Ctrlbox6 = GUICtrlCreateCheckbox("Ctrl + 6", 180, 240, 70, 17)
$Ctrlbox7 = GUICtrlCreateCheckbox("Ctrl + 7", 180, 264, 70, 17)
$Ctrlbox8 = GUICtrlCreateCheckbox("Ctrl + 8", 180, 288, 70, 17)
$Ctrlbox9 = GUICtrlCreateCheckbox("Ctrl + 9", 180, 312, 70, 17)
$Ctrlinput0 = GUICtrlCreateInput("None", 255, 96, 190, 17)
$Ctrlinput1 = GUICtrlCreateInput("亲,为了更好的为您服务,请问【%s】是您的游戏账户吗?", 255, 120, 190, 17)
$Ctrlinput2 = GUICtrlCreateInput("None", 255, 144, 190, 17)
$Ctrlinput3 = GUICtrlCreateInput("None", 255, 168, 190, 17)
$Ctrlinput4 = GUICtrlCreateInput("None", 255, 192, 190, 17)
$Ctrlinput5 = GUICtrlCreateInput("None", 255, 216, 190, 17)
$Ctrlinput6 = GUICtrlCreateInput("None", 255, 240, 190, 17)
$Ctrlinput7 = GUICtrlCreateInput("None", 255, 264, 190, 17)
$Ctrlinput8 = GUICtrlCreateInput("None", 255, 288, 190, 17)
$Ctrlinput9 = GUICtrlCreateInput("None", 255, 312, 190, 17)
For $i = 1 To 100
$var[$i] = RegRead("HKEY_CURRENT_USER\keyboard layout\preload", $i)
If Not $var[$i] Then
$var = $i - 1
ExitLoop
EndIf
Next
For $i = 1 To $var
$ime[$i] = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Keyboard Layouts\" & $var[$i], "Layout Text")
If $ime[$i] Then $imee = $imee & $ime[$i] & "|"
Next
If StringRight($imee, 1) = "|"Then $imee = StringTrimRight($imee, 1)
GUICtrlSetData($Language1, $imee, 0)
GUICtrlSetData($Language2, $imee, 0)
GUICtrlSetData($Altbo0, $keylist, "Alt + 1")
GUICtrlSetData($Altbo1, $keylist, 0)
GUICtrlSetData($Altbo2, $keylist, "Alt + 2")
GUICtrlSetData($Altbo3, $keylist, "Alt + 3")
GUICtrlSetData($Altbo4, $keylist, 0)
GUICtrlSetData($Altbo5, $keylist, 0)
GUICtrlSetData($Altbo6, $keylist, 0)
GUICtrlSetData($Altbo7, $keylist, 0)
GUICtrlSetData($Altbo8, $keylist, 0)
GUICtrlSetData($Altbo9, $keylist, 0)
If GUICtrlRead($Ctrlbox0) = 1 Then HotKeySet("^0","SendCtrlMsg0")
If GUICtrlRead($Ctrlbox1) = 1 Then HotKeySet("^1","SendCtrlMsg1")
If GUICtrlRead($Ctrlbox2) = 1 Then HotKeySet("^2","SendCtrlMsg2")
If GUICtrlRead($Ctrlbox3) = 1 Then HotKeySet("^3","SendCtrlMsg3")
If GUICtrlRead($Ctrlbox4) = 1 Then HotKeySet("^4","SendCtrlMsg4")
If GUICtrlRead($Ctrlbox5) = 1 Then HotKeySet("^5","SendCtrlMsg5")
If GUICtrlRead($Ctrlbox6) = 1 Then HotKeySet("^6","SendCtrlMsg6")
If GUICtrlRead($Ctrlbox7) = 1 Then HotKeySet("^7","SendCtrlMsg7")
If GUICtrlRead($Ctrlbox8) = 1 Then HotKeySet("^8","SendCtrlMsg8")
If GUICtrlRead($Ctrlbox9) = 1 Then HotKeySet("^9","SendCtrlMsg9")
If GUICtrlRead($Altbo0) <> "None" Then $AltHKS0 = "!" & StringRight(GUICtrlRead($Altbo0),1)
If GUICtrlRead($Altbo1) <> "None" Then $AltHKS1 = "!" & StringRight(GUICtrlRead($Altbo1),1)
If GUICtrlRead($Altbo2) <> "None" Then $AltHKS2 = "!" & StringRight(GUICtrlRead($Altbo2),1)
If GUICtrlRead($Altbo3) <> "None" Then $AltHKS3 = "!" & StringRight(GUICtrlRead($Altbo3),1)
If GUICtrlRead($Altbo4) <> "None" Then $AltHKS4 = "!" & StringRight(GUICtrlRead($Altbo4),1)
If GUICtrlRead($Altbo5) <> "None" Then $AltHKS5 = "!" & StringRight(GUICtrlRead($Altbo5),1)
If GUICtrlRead($Altbo6) <> "None" Then $AltHKS6 = "!" & StringRight(GUICtrlRead($Altbo6),1)
If GUICtrlRead($Altbo7) <> "None" Then $AltHKS7 = "!" & StringRight(GUICtrlRead($Altbo7),1)
If GUICtrlRead($Altbo8) <> "None" Then $AltHKS8 = "!" & StringRight(GUICtrlRead($Altbo8),1)
If GUICtrlRead($Altbo9) <> "None" Then $AltHKS9 = "!" & StringRight(GUICtrlRead($Altbo9),1)
If GUICtrlRead($Altbox0) = 1 And GUICtrlRead($Altbo0) <> "None" Then
HotKeySet($AltHKS0,"SendAltMsg0")
GUICtrlSetState($Altbo0,128)
Else
GUICtrlSetState($Altbox0,4)
EndIf
If GUICtrlRead($Altbox1) = 1 And GUICtrlRead($Altbo1) <> "None" Then
HotKeySet($AltHKS1,"SendAltMsg1")
GUICtrlSetState($Altbo1,128)
Else
GUICtrlSetState($Altbox1,4)
EndIf
If GUICtrlRead($Altbox2) = 1 And GUICtrlRead($Altbo2) <> "None" Then
HotKeySet($AltHKS2,"SendAltMsg2")
GUICtrlSetState($Altbo2,128)
Else
GUICtrlSetState($Altbox2,4)
EndIf
If GUICtrlRead($Altbox3) = 1 And GUICtrlRead($Altbo3) <> "None" Then
HotKeySet($AltHKS3,"SendAltMsg3")
GUICtrlSetState($Altbo3,128)
Else
GUICtrlSetState($Altbox3,4)
EndIf
If GUICtrlRead($Altbox4) = 1 And GUICtrlRead($Altbo4) <> "None" Then
HotKeySet($AltHKS4,"SendAltMsg4")
GUICtrlSetState($Altbo4,128)
Else
GUICtrlSetState($Altbox4,4)
EndIf
If GUICtrlRead($Altbox5) = 1 And GUICtrlRead($Altbo5) <> "None" Then
HotKeySet($AltHKS5,"SendAltMsg5")
GUICtrlSetState($Altbo5,128)
Else
GUICtrlSetState($Altbox5,4)
EndIf
If GUICtrlRead($Altbox6) = 1 And GUICtrlRead($Altbo6) <> "None" Then
HotKeySet($AltHKS6,"SendAltMsg6")
GUICtrlSetState($Altbo6,128)
Else
GUICtrlSetState($Altbox6,4)
EndIf
If GUICtrlRead($Altbox7) = 1 And GUICtrlRead($Altbo7) <> "None" Then
HotKeySet($AltHKS7,"SendAltMsg7")
GUICtrlSetState($Altbo7,128)
Else
GUICtrlSetState($Altbox7,4)
EndIf
If GUICtrlRead($Altbox8) = 1 And GUICtrlRead($Altbo8) <> "None" Then
HotKeySet($AltHKS8,"SendAltMsg8")
GUICtrlSetState($Altbo8,128)
Else
GUICtrlSetState($Altbox8,4)
EndIf
If GUICtrlRead($Altbox9) = 1 And GUICtrlRead($Altbo9) <> "None" Then
HotKeySet($AltHKS9,"SendAltMsg9")
GUICtrlSetState($Altbo9,128)
Else
GUICtrlSetState($Altbox9,4)
EndIf
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Altbox0
If GUICtrlRead($Altbox0) = 1 Then
If GUICtrlRead($Altbo0) <> "None" Then
$AltHKS0 = "!" & StringRight(GUICtrlRead($Altbo0),1)
GUICtrlSetState($Altbo0,128)
HotKeySet($AltHKS0,"SendAltMsg0")
Else
GUICtrlSetState($Altbox0,4)
MsgBox(0,"警告","A → 0 未设置热键")
EndIf
Else
HotKeySet($AltHKS0)
GUICtrlSetState($Altbo0,64)
EndIf
Case $Altbox1
If GUICtrlRead($Altbox1) = 1 Then
If GUICtrlRead($Altbo1) <> "None" Then
$AltHKS1 = "!" & StringRight(GUICtrlRead($Altbo1),1)
GUICtrlSetState($Altbo1,128)
HotKeySet($AltHKS1,"SendAltMsg1")
Else
GUICtrlSetState($Altbox1,4)
MsgBox(0,"警告","A → 1 未设置热键")
EndIf
Else
HotKeySet($AltHKS1)
GUICtrlSetState($Altbo1,64)
EndIf
Case $Altbox2
If GUICtrlRead($Altbox2) = 1 Then
If GUICtrlRead($Altbo2) <> "None" Then
$AltHKS2 = "!" & StringRight(GUICtrlRead($Altbo2),1)
GUICtrlSetState($Altbo2,128)
HotKeySet($AltHKS2,"SendAltMsg2")
Else
GUICtrlSetState($Altbox2,4)
MsgBox(0,"警告","A → 2 未设置热键")
EndIf
Else
HotKeySet($AltHKS2)
GUICtrlSetState($Altbo2,64)
EndIf
Case $Altbox3
If GUICtrlRead($Altbox3) = 1 Then
If GUICtrlRead($Altbo3) <> "None" Then
$AltHKS3 = "!" & StringRight(GUICtrlRead($Altbo3),1)
GUICtrlSetState($Altbo3,128)
HotKeySet($AltHKS3,"SendAltMsg3")
Else
GUICtrlSetState($Altbox3,4)
MsgBox(0,"警告","A → 3 未设置热键")
EndIf
Else
HotKeySet($AltHKS3)
GUICtrlSetState($Altbo3,64)
EndIf
Case $Altbox4
If GUICtrlRead($Altbox4) = 1 Then
If GUICtrlRead($Altbo4) <> "None" Then
$AltHKS4 = "!" & StringRight(GUICtrlRead($Altbo4),1)
GUICtrlSetState($Altbo4,128)
HotKeySet($AltHKS4,"SendAltMsg4")
Else
GUICtrlSetState($Altbox4,4)
MsgBox(0,"警告","A → 4 未设置热键")
EndIf
Else
HotKeySet($AltHKS4)
GUICtrlSetState($Altbo4,64)
EndIf
Case $Altbox5
If GUICtrlRead($Altbox5) = 1 Then
If GUICtrlRead($Altbo5) <> "None" Then
$AltHKS5 = "!" & StringRight(GUICtrlRead($Altbo5),1)
GUICtrlSetState($Altbo5,128)
HotKeySet($AltHKS5,"SendAltMsg5")
Else
GUICtrlSetState($Altbox5,4)
MsgBox(0,"警告","A → 5 未设置热键")
EndIf
Else
HotKeySet($AltHKS5)
GUICtrlSetState($Altbo5,64)
EndIf
Case $Altbox6
If GUICtrlRead($Altbox6) = 1 Then
If GUICtrlRead($Altbo6) <> "None" Then
$AltHKS6 = "!" & StringRight(GUICtrlRead($Altbo6),1)
GUICtrlSetState($Altbo6,128)
HotKeySet($AltHKS6,"SendAltMsg6")
Else
GUICtrlSetState($Altbox6,4)
MsgBox(0,"警告","A → 6 未设置热键")
EndIf
Else
HotKeySet($AltHKS6)
GUICtrlSetState($Altbo6,64)
EndIf
Case $Altbox7
If GUICtrlRead($Altbox7) = 1 Then
If GUICtrlRead($Altbo7) <> "None" Then
$AltHKS7 = "!" & StringRight(GUICtrlRead($Altbo7),1)
GUICtrlSetState($Altbo7,128)
HotKeySet($AltHKS7,"SendAltMsg7")
Else
GUICtrlSetState($Altbox7,4)
MsgBox(0,"警告","A → 7 未设置热键")
EndIf
Else
HotKeySet($AltHKS7)
GUICtrlSetState($Altbo7,64)
EndIf
Case $Altbox8
If GUICtrlRead($Altbox8) = 1 Then
If GUICtrlRead($Altbo8) <> "None" Then
$AltHKS8 = "!" & StringRight(GUICtrlRead($Altbo8),1)
GUICtrlSetState($Altbo8,128)
HotKeySet($AltHKS8,"SendAltMsg8")
Else
GUICtrlSetState($Altbox8,4)
MsgBox(0,"警告","A → 8 未设置热键")
EndIf
Else
HotKeySet($AltHKS8)
GUICtrlSetState($Altbo8,64)
EndIf
Case $Altbox9
If GUICtrlRead($Altbox9) = 1 Then
If GUICtrlRead($Altbo9) <> "None" Then
$AltHKS9 = "!" & StringRight(GUICtrlRead($Altbo9),1)
GUICtrlSetState($Altbo9,128)
HotKeySet($AltHKS9,"SendAltMsg9")
Else
GUICtrlSetState($Altbox9,4)
MsgBox(0,"警告","A → 9 未设置热键")
EndIf
Else
HotKeySet($AltHKS9)
GUICtrlSetState($Altbo9,64)
EndIf
Case $Ctrlbox0
If GUICtrlRead($Ctrlbox0) = 1 Then
HotKeySet("^0","SendCtrlMsg0")
Else
HotKeySet("^0")
EndIf
Case $Ctrlbox1
If GUICtrlRead($Ctrlbox1) = 1 Then
HotKeySet("^1","SendCtrlMsg1")
Else
HotKeySet("^1")
EndIf
Case $Ctrlbox2
If GUICtrlRead($Ctrlbox2) = 1 Then
HotKeySet("^2","SendCtrlMsg2")
Else
HotKeySet("^2")
EndIf
Case $Ctrlbox3
If GUICtrlRead($Ctrlbox3) = 1 Then
HotKeySet("^3","SendCtrlMsg3")
Else
HotKeySet("^3")
EndIf
Case $Ctrlbox4
If GUICtrlRead($Ctrlbox4) = 1 Then
HotKeySet("^4","SendCtrlMsg4")
Else
HotKeySet("^4")
EndIf
Case $Ctrlbox5
If GUICtrlRead($Ctrlbox5) = 1 Then
HotKeySet("^5","SendCtrlMsg5")
Else
HotKeySet("^5")
EndIf
Case $Ctrlbox6
If GUICtrlRead($Ctrlbox6) = 1 Then
HotKeySet("^6","SendCtrlMsg6")
Else
HotKeySet("^6")
EndIf
Case $Ctrlbox7
If GUICtrlRead($Ctrlbox7) = 1 Then
HotKeySet("^7","SendCtrlMsg7")
Else
HotKeySet("^7")
EndIf
Case $Ctrlbox8
If GUICtrlRead($Ctrlbox8) = 1 Then
HotKeySet("^8","SendCtrlMsg8")
Else
HotKeySet("^8")
EndIf
Case $Ctrlbox9
If GUICtrlRead($Ctrlbox9) = 1 Then
HotKeySet("^9","SendCtrlMsg9")
Else
HotKeySet("^9")
EndIf
EndSwitch
WEnd
Func SendCtrlMsg0()
FixMsg(GUICtrlRead($Ctrlinput0))
EndFunc
Func SendCtrlMsg1()
FixMsg(GUICtrlRead($Ctrlinput1))
EndFunc
Func SendCtrlMsg2()
FixMsg(GUICtrlRead($Ctrlinput2))
EndFunc
Func SendCtrlMsg3()
FixMsg(GUICtrlRead($Ctrlinput3))
EndFunc
Func SendCtrlMsg4()
FixMsg(GUICtrlRead($Ctrlinput4))
EndFunc
Func SendCtrlMsg5()
FixMsg(GUICtrlRead($Ctrlinput5))
EndFunc
Func SendCtrlMsg6()
FixMsg(GUICtrlRead($Ctrlinput6))
EndFunc
Func SendCtrlMsg7()
FixMsg(GUICtrlRead($Ctrlinput7))
EndFunc
Func SendCtrlMsg8()
FixMsg(GUICtrlRead($Ctrlinput8))
EndFunc
Func SendCtrlMsg9()
FixMsg(GUICtrlRead($Ctrlinput9))
EndFunc
Func FixMsg($FixString)
If StringInStr($FixString, "%s") Then
Local $sData = StringRegExpReplace(ClipGet(), ' | | ', '')
If StringLeft($sData, 2) <> "tb" Then $sData = "tb" & $sData
$Msg = StringRegExpReplace($FixString, '%s', $sData)
Else
$sData = ClipGet()
$Msg = $FixString
EndIf
ClipPut($Msg)
Send("^v")
ClipPut($sData)
EndFunc
Func SendAltMsg0()
MsgBox(0,0,0)
EndFunc
Func SendAltMsg1()
MsgBox(0,0,0)
EndFunc
Func SendAltMsg2()
MsgBox(0,0,0)
EndFunc
Func SendAltMsg3()
MsgBox(0,0,0)
EndFunc
Func SendAltMsg4()
MsgBox(0,0,0)
EndFunc
Func SendAltMsg5()
MsgBox(0,0,0)
EndFunc
Func SendAltMsg6()
MsgBox(0,0,0)
EndFunc
Func SendAltMsg7()
MsgBox(0,0,0)
EndFunc
Func SendAltMsg8()
MsgBox(0,0,0)
EndFunc
Func SendAltMsg9()
MsgBox(0,0,0)
EndFunc 选好快捷键之后用 IniWrite("文件名", "字段", "关键字", "值")
初始化时候用IniRead("文件名", "字段名", "关键字", "默认值")
然后GUICtrlSetData() 还是不明白
页:
[1]