If
End Sub
Private Sub cmbChooseKey_KeyUp(Index As Integer, KeyCode As Integer, Shift As Integer)
unLockcombobox
End Sub
''把键面字符转变成相应的键盘扫描码
Private Function strKeyToLong(strKey As String) As Integer
Dim i As Long
Select Case strKey
Case "F2"
i = vbKeyF2
Case "F3"
i = vbKeyF3
Case "F4"
i = vbKeyF4
Case "F5"
i = vbKeyF5
Case "F6"
i = vbKeyF6
Case "F7"
i = vbKeyF7
Case "F8"
i = vbKeyF8
Case "F9"
i = vbKeyF9
Case "F10"
i = vbKeyF10
Case "F11"
i = vbKeyF11
End Select
strKeyToLong = i
End Function
Private Sub cmbChooseKey_Click(Index As Integer)
''禁止重复定义快捷键
RedefineFuncKey cmbChooseKey(Index).Text, Index
End Sub
Private Sub cmdAdd_Click()
Dim strFileName As String
If cmbChooseKey(5).Text = "无" Or cmbChooseKey(5).Text = "" Then
MsgBox "请先为应用
程序定义一个快捷键", vbInformation, "提示"
Else
cmnAdd.DialogTitle = "添加"
cmnAdd.Filter = "可执行文件(*.exe)|*.exe" ''在添加对话框中只显示EXE文件
cmnAdd.ShowOpen ''打开添加对话框
strFileName = cmnAdd.FileName
''把定义的快捷键和应用
程序添加到列表框中
If strFileName <> "" Then
List1.AddItem cmbChooseKey(5).Text + " " + cmnAdd.FileName
End If
cmbChooseKey(5).Text = "无"
End If
End Sub
Private Sub cmdApply_Click()
Dim strKeyJoin As String, strKeyFile As String
strKeyJoin = ""
strKeyFile = ""
''把特定功能区定义的快捷键以逗号为分隔符写入FunctionKey.txt文件
For i = 0 To 4
If i < 4 Then
strKeyJoin = strKeyJoin & Trim(cmbChooseKey(i).Text) & ","
Else
strKeyJoin = strKeyJoin & Trim(cmbChooseKey(i).Text)
End If
Next
Open App.Path + "\FunctionKey.txt" For Output As #1
Print #1, strKeyJoin
Close #1
''如果在列表框中有应用程序名和快捷键且检测CustomKey.txt,则删除该文件;
If List1.ListCount = 0 And Dir(App.Path + "\CustomKey.txt") <> "" Then
Kill App.Path + "\CustomKey.txt"
''把定义的快捷键及应用程序以逗号为分隔符写入CustomKey.txt文件
ElseIf List1.ListCount <> 0 Then
For i = 0 To List1.ListCount - 1
If i < List1.ListCount - 1 Then
rKeyFile = strKeyFile + List1.List(i) + ","
Else
strKeyFile = strKeyFile + List1.List(i)
End If
Next
Open App.Path + "\CustomKey.txt" For Output As #1
Print #1, strKeyFile
Close #1
End If
List1.Clear
''重新从FunctionKey.txt和CustomKey.txt文件中取得定义的快捷键及相应的应用程序名供程序使用
Form_Load
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
''删除列表框中选中的快捷键和应用程序名
Private Sub cmdDel_Click()
List1.RemoveItem List1.ListIndex
End Sub
Private Sub cmdOk_Click()
cmdApply_Click ''调用"应用"按钮下的代码
Me.Visible = False
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
''按快捷键A调用"应用"按钮下的代码
If KeyCode = vbKeyA Then
cmdApply_Click
End If
End Sub
Private Sub Form_Load()
Dim strLine As String
''把F2~F11和"无"分别添加到组合框控件数组的下拉列表框和文本框中
For i = 0 To 5
cmbChooseKey(i).Text =