Если делать так:
- Код: Выделить всё
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
.....
End If
End Sub
то получается назначить только одну клавишу.
Кто знает, как быть?
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
.....
End If
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 75 And Shift = 2 Then
MsgBox "Ctrl+K"
End If
End Sub
Amed писал(а):
- Код: Выделить всё
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 75 And Shift = 2 Then
MsgBox "Ctrl+K"
End If
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = vbAltMask+vbCtrlMask Then
MsgBox "Alt+Ctrl"
End If
End Sub
MSDN писал(а):If you need to test for the shift argument, you can use the shift constants which define the bits within the argument. The constants have the following values:
- Код: Выделить всё
Constant Value Description
vbShiftMask 1 SHIFT key bit mask.
VbCtrlMask 2 CTRL key bit mask.
VbAltMask 4 ALT key bit mask.
The constants act as bit masks that you can use to test for any combination of keys.
Object Browser писал(а):Const vbAltMask = 4
Member of VBRUN.ShiftConstants
Alt key bit mask.
Const vbCtrlMask = 2
Member of VBRUN.ShiftConstants
Ctrl key bit mask.
Const vbShiftMask = 1
Member of VBRUN.ShiftConstants
Shift key bit mask.
GSerg писал(а):Лучше добавлять в коллекцию айтемы по ключу KeyCode<<16 | Shift, а потом проверять, нет ли их там...
Amed писал(а):Я заглянул в Object Browser первым делом .
Select Case RecognizeKeyCode(KeyCode, Shift)
Case "Ctrl+1"
MsgBox ...
End Select
Function RecognizeKeyCode(KeyCode As Integer, Shift As Integer) As String
Dim Z As String, K As String
If KeyCode = 0 Then Exit Function
Z = ""
If (Shift And vbCtrlMask) = vbCtrlMask Then Z = Z & IIf(Len(Z) > 0, "+", "") & "Ctrl"
If (Shift And vbAltMask) = vbAltMask Then Z = Z & IIf(Len(Z) > 0, "+", "") & "Alt"
If (Shift And vbShiftMask) = vbShiftMask Then Z = Z & IIf(Len(Z) > 0, "+", "") & "Shift"
Select Case KeyCode
Case KeyCodeConstants.vbKey0 To KeyCodeConstants.vbKey9
K = Chr$(Asc("0") + KeyCode - KeyCodeConstants.vbKey0)
Case KeyCodeConstants.vbKeyA To KeyCodeConstants.vbKeyZ
K = Chr$(Asc("A") + KeyCode - KeyCodeConstants.vbKeyA)
Case KeyCodeConstants.vbKeyF1 To KeyCodeConstants.vbKeyF16
K = "F" & Trim$(Str$(KeyCode - KeyCodeConstants.vbKeyF1 + 1))
Case KeyCodeConstants.vbKeyNumpad0 To KeyCodeConstants.vbKeyNumpad9
K = "Num" & Chr$(Asc("0") + KeyCode - KeyCodeConstants.vbKeyNumpad0)
Case KeyCodeConstants.vbKeyAdd
K = "Gray+"
Case KeyCodeConstants.vbKeyBack
K = "BS"
Case KeyCodeConstants.vbKeyCancel
K = "Cancel"
Case KeyCodeConstants.vbKeyCapital
K = "CapsLock"
Case KeyCodeConstants.vbKeyClear
K = "Clear"
Case KeyCodeConstants.vbKeyControl
K = "" 'Ctrl
Case KeyCodeConstants.vbKeyDecimal
K = "Gray."
Case KeyCodeConstants.vbKeyDivide
K = "Gray/"
Case KeyCodeConstants.vbKeyDown
K = "Down"
Case KeyCodeConstants.vbKeyEnd
K = "End"
Case KeyCodeConstants.vbKeyEscape
K = "ESC"
Case KeyCodeConstants.vbKeyExecute
K = "Exec"
Case KeyCodeConstants.vbKeyHelp
K = "Help"
Case KeyCodeConstants.vbKeyHome
K = "Home"
Case KeyCodeConstants.vbKeyInsert
K = "Ins"
Case KeyCodeConstants.vbKeyDelete
K = "Del"
Case KeyCodeConstants.vbKeyLButton
K = "" 'Mouse: Left button
Case KeyCodeConstants.vbKeyLeft
K = "Left"
Case KeyCodeConstants.vbKeyMButton
K = "" 'Mouse: Middle button
Case KeyCodeConstants.vbKeyMenu
K = "" 'Alt (Menu)
Case KeyCodeConstants.vbKeyMultiply
K = "Gray*"
Case KeyCodeConstants.vbKeyNumlock
K = "NumLock"
Case KeyCodeConstants.vbKeyPageDown
K = "PgDn"
Case KeyCodeConstants.vbKeyPageUp
K = "PgUp"
Case KeyCodeConstants.vbKeyPause
K = "Pause"
Case KeyCodeConstants.vbKeyPrint
K = "Print"
Case KeyCodeConstants.vbKeyRButton
K = "" 'Mouse: Right button
Case KeyCodeConstants.vbKeyReturn
K = "Enter"
Case KeyCodeConstants.vbKeyRight
K = "Right"
Case KeyCodeConstants.vbKeyScrollLock
K = "ScrollLock"
Case KeyCodeConstants.vbKeySelect
K = "Select"
Case KeyCodeConstants.vbKeySeparator
K = "GrayEnter"
Case KeyCodeConstants.vbKeyShift
K = "" 'Shift
Case KeyCodeConstants.vbKeySnapshot
K = "Snapshot"
Case KeyCodeConstants.vbKeySpace
K = "Space"
Case KeyCodeConstants.vbKeySubtract
K = "Gray-"
Case KeyCodeConstants.vbKeyTab
K = "Tab"
Case KeyCodeConstants.vbKeyUp
K = "Up"
Case 192
K = "`"
Case 189
K = "-"
Case 187
K = "="
Case 219
K = "["
Case 221
K = "]"
Case 186
K = ";"
Case 222
K = "'"
Case 220
K = "\"
Case 93
K = "Menu"
Case Else
K = ""
End Select
If Len(K) > 0 And Len(Z) > 0 Then K = "+" & K
RecognizeKeyCode = Z & K
End Function
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 79