I'm not sure how you would do that. Assuming that you've added a button to the toolbar then you can only send it to a subroutine without any key info. Could you just add two buttons?
There are much too many buttons (49 in a custom toolbar). For every one I plan to launch a macro. If CTRL is pressed I decrease a certain variable. If CTRL isn't pressed, I increase it.
I presume it should be somehow related to the keycode but I still do not know how to get it...
Maybe after at a kind of "press down" event. Have to search for that.
hi at,
Are you asking about the SENDKEYS statement in Visual Basic,??
You can precede a Key code with Control key code to select an alternative action.
E
In fact Eric, I need to find the way to know if CTRL is pressed or not, once a left-click happens so I increase or decrease a variable inside the assigned macro.
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Dim temp As Integer
temp = GetKeyState(vbKeyControl)
If temp = -127 Or temp = -128 Then MsgBox ("Control Pressed")
Gracias Pommie, late in the night I found the right wording: "testing CTRL key" and a solution similar to yours.
Code:
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Const VK_CONTROL As Integer = &H11 'Ctrl
Sub test()
If GetKeyState(VK_CONTROL) < 0 Then Ctrl = True Else Ctrl = False
If Ctrl = True Then
Range("H7").Select
ActiveCell.Value = "apretada"
Else
Range("H7").Select
ActiveCell.Value = "sin apretar"
End If
End Sub
One day I will try to understand why they need to deal with negative values to test keys. Certainly not intuitive.