I know how to do a CommandButton_Click() event and I have a
CommandButton_KeyDown() event which checks to see if Ctrl was held down:
Private Sub Note_Toggle_KeyDown(KeyCode As Integer, Shift As Integer)
If (Shift And acCtrlMask) > 0 Then
Call TheLocker("[Notes Subform]", "[Note Toggle]", "[Text_EditNotes]")
End If
End Sub
The problem is that the Click and the KeyDown are seperate. Currently, the
KeyDown event fires after clicking on the object to give it focus then
pressing Ctrl once. If the user presses Ctrl and holds it down while
clicking the mouse button, then the two events appear to be connected. But
I'm sure that somewhere along the line, my expectations of what the user is
going to do and what actually happens will not be the same. So, I want to
have something happen when the user holds down Ctrl and then clicks the mouse
button on a command button while holding the Ctrl button down.
I'm looking for some sort of Button_ClickKeyDown().
Ron Weiner - 15 Feb 2006 00:13 GMT
The way I have always done this is to test to see of the Control Key is
pressed in the click event of the button. Here is some code
In a Module somewhere
Const VK_SHIFT = &H10
Const VK_CONTROL = &H11
Const VK_ALT = &H12
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As
Integer
In the Click Event of your Button
If (GetKeyState(VK_CONTROL) And &HF0000000) Then
' Do what the button does when the Control key IS Pressed
Else
' Do what the button does when the Control key is NOT Pressed
End If
To test for the Shift or Alt Keys Substuite VK_SHIFT or VK_ALT for
VK_CONTROL

Signature
Ron W
www.WorksRite.com
> I know how to do a CommandButton_Click() event and I have a
> CommandButton_KeyDown() event which checks to see if Ctrl was held down:
[quoted text clipped - 14 lines]
>
> I'm looking for some sort of Button_ClickKeyDown().
Banaticus - 15 Feb 2006 00:57 GMT
Thanks for your help.
Don't I have to put End Function after that function or have it return some
value?
I created a module named "KeyPressConstants" and put the public information
into it. I then added the following to a new form that only has a single
command button and image on it:
Private Sub ToggleThing_Click()
If (GetKeyState(VK_CONTROL) And &HF0000000) Then
Me.BlueThing.Visible = True
Else
Me.BlueThing.Visible = False
End If
End Sub
I set the image to be hidden then started the form in Form View. The image
isn't becoming visible when I hold Ctrl and click the mouse button, darn it.
Ron Weiner - 15 Feb 2006 02:00 GMT
Try this
Create a new form and add the following controls:
Command Button Named Command0
Label Control Named Label1
Open the code window for the form and paste the following
Option Compare Database
Option Explicit
Const VK_CONTROL = &H11
Private Declare Function GetKeyState Lib _
"user32" (ByVal nVirtKey As Long) As Integer
Private Sub Command0_Click()
If (GetKeyState(VK_CONTROL) And &HF0000000) Then
Label1.Caption = "Control Key Down"
Else
Label1.Caption = "Control Key NOT Down"
End If
End Sub
Exercise the form by pushing the button with and without the Control key
being pressed.

Signature
Ron W
www.WorksRite.com
> Thanks for your help.
> Don't I have to put End Function after that function or have it return some
[quoted text clipped - 13 lines]
> I set the image to be hidden then started the form in Form View. The image
> isn't becoming visible when I hold Ctrl and click the mouse button, darn it.