Key modifier for double-click event?

  • Thread starter Thread starter Byrt Martinez
  • Start date Start date
B

Byrt Martinez

Is it possible to detect if a key is held down during th
BeforeDoubleClick event?

I want to be able to change a cell with a double-click, but no
interfere with the normal edit formula default functionality. I want t
be able to hold down the CTRL key while double-clicking the cell to ge
different behavior. Is this possible?

TIA,

-
 
Byrt,

I believe you are going to have to use a key other than the Ctrl or Shift key.
The Alt key will work...

'1. Place the following line of code at the top of a general module:

Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As
Integer

'2. Then your code in the double click event for the sheet could look like
this:
'--------------------------------------------
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
If GetKeyState(18) < 0 Then
'more code
MsgBox "Alt key is down"
Else
'more code
MsgBox "Alt key is up"
End If
Cancel = True
End Sub
'---------------------------------------------

The Shift key is "16", the Ctrl key is "17" and
the Alt key is "18".

Regards,
Jim Cone
San Francisco, CA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top