vb全局热键自定义键
比如vb用到全局热键,一般都是vbkey后面加上某键(比如vbkeyF1),不过我想让这个“F1”自己定义,比如“F1”是text中的内容,我试过(vbkey&text1...
比如vb用到全局热键,一般都是vbkey后面加上某键(比如vbkeyF1),不过我想让这个“F1”自己定义,比如“F1”是text中的内容,我试过(vbkey & text1.text),只是不行.谢谢!
展开
3个回答
展开全部
本人早期写的两个比较笨的函数,应该可以解决你提的问题:
Public Function GetKeyName(iKeyCode As Integer) As String
Dim KM(0 To 255) As String
KM(1) = "MouseLeftButton"
KM(2) = "MouseRightButton"
KM(3) = "Cancel"
KM(4) = "MouseMiddleButton"
KM(8) = "BackSpace"
KM(9) = "Tab"
KM(12) = "Clear"
KM(13) = "Enter"
KM(16) = "Shift"
KM(17) = "Ctrl"
KM(18) = "Menu"
KM(19) = "Pause"
KM(20) = "CapsLock"
KM(27) = "ESC"
KM(32) = "SpaceBar"
KM(33) = "PageUp"
KM(34) = "PageDown"
KM(35) = "End"
KM(36) = "Home"
KM(37) = "LeftArrow"
KM(38) = "UpArrow"
KM(39) = "RightArrow"
KM(40) = "DownArrow"
KM(41) = "Select"
KM(42) = "PrintScreen"
KM(43) = "Execute"
KM(44) = "SnopShot"
KM(45) = "Ins"
KM(46) = "Del"
KM(47) = "Help"
KM(144) = "NumLock"
For i = 65 To 90
KM(i) = Chr(i)
Next i
For i = 48 To 57
KM(i) = Chr(i)
Next i
For i = 96 To 105
KM(i) = "Numpad" + CStr(i - 96)
Next i
KM(91) = "WinLeftKey"
KM(92) = "WinRightKey"
KM(93) = "WinMenuKey"
KM(106) = "(*)Multiply"
KM(107) = "(+)Add"
KM(108) = "Separator"
KM(110) = "(.)Decunal"
KM(109) = "(-)Subtract"
KM(111) = "(/)Divide"
KM(145) = "ScrollLock"
KM(186) = ";"
KM(187) = "="
KM(188) = ","
KM(189) = "-"
KM(190) = "."
KM(191) = "/"
KM(192) = "`"
KM(219) = "["
KM(221) = "]"
KM(220) = "\"
KM(222) = "'"
For i = 112 To 127
KM(i) = "F" + CStr(i - 111)
Next
GetKeyName = KM(iKeyCode)
Erase KM
End Function
Public Function GetKeyCode(iKeyName As String) As Integer
Dim KM(0 To 255) As String
KM(1) = "MouseLeftButton"
KM(2) = "MouseRightButton"
KM(3) = "Cancel"
KM(4) = "MouseMiddleButton"
KM(8) = "BackSpace"
KM(9) = "Tab"
KM(12) = "Clear"
KM(13) = "Enter"
KM(16) = "Shift"
KM(17) = "Ctrl"
KM(18) = "Menu"
KM(19) = "Pause"
KM(20) = "CapsLock"
KM(27) = "ESC"
KM(32) = "SpaceBar"
KM(33) = "PageUp"
KM(34) = "PageDown"
KM(35) = "End"
KM(36) = "Home"
KM(37) = "LeftArrow"
KM(38) = "UpArrow"
KM(39) = "RightArrow"
KM(40) = "DownArrow"
KM(41) = "Select"
KM(42) = "PrintScreen"
KM(43) = "Execute"
KM(44) = "SnopShot"
KM(45) = "Ins"
KM(46) = "Del"
KM(47) = "Help"
KM(144) = "NumLock"
For i = 65 To 90
KM(i) = Chr(i)
Next i
For i = 48 To 57
KM(i) = Chr(i)
Next i
For i = 96 To 105
KM(i) = "Numpad" + CStr(i - 96)
Next i
KM(106) = "(*)Multiply"
KM(107) = "(+)Add"
KM(108) = "Separator"
KM(110) = "(.)Decunal"
KM(109) = "(-)Subtract"
KM(111) = "(/)Divide"
For i = 112 To 127
KM(i) = "F" + CStr(i - 111)
Next
For i = 0 To 255
If UCase(iKeyName) = KM(i) Then
GetKeyCode = i
End If
Next i
If i >= 255 Then
GetKeyCode = 0
End If
Erase KM
End Function
Public Function GetKeyName(iKeyCode As Integer) As String
Dim KM(0 To 255) As String
KM(1) = "MouseLeftButton"
KM(2) = "MouseRightButton"
KM(3) = "Cancel"
KM(4) = "MouseMiddleButton"
KM(8) = "BackSpace"
KM(9) = "Tab"
KM(12) = "Clear"
KM(13) = "Enter"
KM(16) = "Shift"
KM(17) = "Ctrl"
KM(18) = "Menu"
KM(19) = "Pause"
KM(20) = "CapsLock"
KM(27) = "ESC"
KM(32) = "SpaceBar"
KM(33) = "PageUp"
KM(34) = "PageDown"
KM(35) = "End"
KM(36) = "Home"
KM(37) = "LeftArrow"
KM(38) = "UpArrow"
KM(39) = "RightArrow"
KM(40) = "DownArrow"
KM(41) = "Select"
KM(42) = "PrintScreen"
KM(43) = "Execute"
KM(44) = "SnopShot"
KM(45) = "Ins"
KM(46) = "Del"
KM(47) = "Help"
KM(144) = "NumLock"
For i = 65 To 90
KM(i) = Chr(i)
Next i
For i = 48 To 57
KM(i) = Chr(i)
Next i
For i = 96 To 105
KM(i) = "Numpad" + CStr(i - 96)
Next i
KM(91) = "WinLeftKey"
KM(92) = "WinRightKey"
KM(93) = "WinMenuKey"
KM(106) = "(*)Multiply"
KM(107) = "(+)Add"
KM(108) = "Separator"
KM(110) = "(.)Decunal"
KM(109) = "(-)Subtract"
KM(111) = "(/)Divide"
KM(145) = "ScrollLock"
KM(186) = ";"
KM(187) = "="
KM(188) = ","
KM(189) = "-"
KM(190) = "."
KM(191) = "/"
KM(192) = "`"
KM(219) = "["
KM(221) = "]"
KM(220) = "\"
KM(222) = "'"
For i = 112 To 127
KM(i) = "F" + CStr(i - 111)
Next
GetKeyName = KM(iKeyCode)
Erase KM
End Function
Public Function GetKeyCode(iKeyName As String) As Integer
Dim KM(0 To 255) As String
KM(1) = "MouseLeftButton"
KM(2) = "MouseRightButton"
KM(3) = "Cancel"
KM(4) = "MouseMiddleButton"
KM(8) = "BackSpace"
KM(9) = "Tab"
KM(12) = "Clear"
KM(13) = "Enter"
KM(16) = "Shift"
KM(17) = "Ctrl"
KM(18) = "Menu"
KM(19) = "Pause"
KM(20) = "CapsLock"
KM(27) = "ESC"
KM(32) = "SpaceBar"
KM(33) = "PageUp"
KM(34) = "PageDown"
KM(35) = "End"
KM(36) = "Home"
KM(37) = "LeftArrow"
KM(38) = "UpArrow"
KM(39) = "RightArrow"
KM(40) = "DownArrow"
KM(41) = "Select"
KM(42) = "PrintScreen"
KM(43) = "Execute"
KM(44) = "SnopShot"
KM(45) = "Ins"
KM(46) = "Del"
KM(47) = "Help"
KM(144) = "NumLock"
For i = 65 To 90
KM(i) = Chr(i)
Next i
For i = 48 To 57
KM(i) = Chr(i)
Next i
For i = 96 To 105
KM(i) = "Numpad" + CStr(i - 96)
Next i
KM(106) = "(*)Multiply"
KM(107) = "(+)Add"
KM(108) = "Separator"
KM(110) = "(.)Decunal"
KM(109) = "(-)Subtract"
KM(111) = "(/)Divide"
For i = 112 To 127
KM(i) = "F" + CStr(i - 111)
Next
For i = 0 To 255
If UCase(iKeyName) = KM(i) Then
GetKeyCode = i
End If
Next i
If i >= 255 Then
GetKeyCode = 0
End If
Erase KM
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
VBkey是VB下的直接地址变量,如果使用内存容器,这样索取地址方式变成了VBREF,所以虚拟机解释语句的时候不能找到正确的指令。解决方案是 定一个OBJECT类型,或者其他类型(没有试验过)的变量来存储 VBKEY***
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
当然不行了,你这样定义相当于是2个变量了,而vbkeyf1是静态的,是物理地址
定义方法都不一样了
楼上2位都说了我想说的了
定义方法都不一样了
楼上2位都说了我想说的了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询