Shift + Click

RichO

Registered Yoozer
Local time
Today, 17:37
Joined
Jan 14, 2004
Messages
1,036
I have a checkbox on my form and I want to be able to detect if shift is being held while clicking the box.

The On Click event of the check box does not recognize KeyCode or KeyAscii - I get an error.

Any ideas on this one?

Thanks
 
why not use "On Key Down" event of the checkbox. i tried and its working:

Private Sub ChkBox_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 16 Then
MsgBox "Shift pressed"
End If
End Sub
 
Last edited:
The Key Down code fires as soon as you press the shift key. I have been able to track when the shift key is pressed but I need to determine if shift is pressed at the time the mouse is clicked on the check box.

I had tried using a boolean variable set by the Key Down event and cleared by the key up event and it works to hold the status of the shift key, until you click. Then for some reason the key up event does not fire after the click event runs and the variable stays true.

I also tried calling the Key Down event from the On Click event to check the status of the shift key but got an "Argument not optional" error.
 
API calls from...

http://www.mentalis.org/apilist/apilist.php

Specifically...

http://www.mentalis.org/apilist/GetAsyncKeyState.shtml


Code:
Option Explicit
Option Compare Text

Private Const conShiftKey As Long = 16

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer


Private Sub chkMyCheckBox_BeforeUpdate(ByRef intCancel As Integer)

    [color=green]'   Required to flush keyboard.[/color]
    GetAsyncKeyState conShiftKey
    
    [color=green]'  0 = Up, -32,768 = Down[/color]
    If GetAsyncKeyState(conShiftKey) = 0 Then
        Me.txtShiftDownStatus = "False"
    Else
        Me.txtShiftDownStatus = "True"
    End If

End Sub
Hope that helps and small A97 demo attached.

Regards,
Chris.
 

Attachments

Thank you.

I though it might be something rather simple that I overlooked but it was a little more involved than I expected. Nonetheless, it works.

Thanks again!
 
You are welcome and also correct.

It might be something simpler and hope it is.

I would prefer to ‘get the job done’ within Access but could not find a way.

But if it works, then it works…

Regards,
Chris.
 

Users who are viewing this thread

Back
Top Bottom