C
Craig Buchanan
i am trying to capture the ctrl-d key combination in the form's
KeyPress/KeyDown events. The KeyAscii value of the KeyPress is 4, when i
would expect 100 ('d') or 68 ('D'). See code below.
Also, is there a 'best practice' for testing keycode combinations (someone
other than a large number of IF THEN ELSE statements)? I'm doing If
KeyAscii = vbKeyD And m_CtrlPressed Then
Can someone share his/her insight?
Thanks,
Craig
<code>
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
' Use bit masks to determine which key was pressed.
m_ShiftPressed = (Shift And acShiftMask) > 0
m_AltPressed = (Shift And acAltMask) > 0
m_CtrlPressed = (Shift And acCtrlMask) > 0
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
' Convert ANSI value to character string.
Dim strCharacter As String: strCharacter = Chr(KeyAscii)
' Convert character to upper case, then to ANSI value.
KeyAscii = Asc(UCase(strCharacter))
If KeyAscii = vbKeyD And m_CtrlPressed Then
MsgBox "delete me"
End If
End Sub
</code>
KeyPress/KeyDown events. The KeyAscii value of the KeyPress is 4, when i
would expect 100 ('d') or 68 ('D'). See code below.
Also, is there a 'best practice' for testing keycode combinations (someone
other than a large number of IF THEN ELSE statements)? I'm doing If
KeyAscii = vbKeyD And m_CtrlPressed Then
Can someone share his/her insight?
Thanks,
Craig
<code>
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
' Use bit masks to determine which key was pressed.
m_ShiftPressed = (Shift And acShiftMask) > 0
m_AltPressed = (Shift And acAltMask) > 0
m_CtrlPressed = (Shift And acCtrlMask) > 0
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
' Convert ANSI value to character string.
Dim strCharacter As String: strCharacter = Chr(KeyAscii)
' Convert character to upper case, then to ANSI value.
KeyAscii = Asc(UCase(strCharacter))
If KeyAscii = vbKeyD And m_CtrlPressed Then
MsgBox "delete me"
End If
End Sub
</code>