I'm trying to detect drag-and-drop events on a script button with qualifier keys held down. I would like to be able to have the script do something based on a drag/drop event with qualifier keys held down, as well as something else on a regular click action.
As a simple test, the following button correctly detects the drag-and-drop event, but not the key which is held down:
Option Explicit
Function OnClick(ByRef clickData)
If ClickData.func.fromdrop Then
If ClickData.func.qualifiers = "none" Then
msgbox "no keys held down"
ElseIf ClickData.func.qualifiers = "ctrl" Then
msgbox "ctrl held down"
End If
Else
msgbox "regular click on button"
End If
End Function
Likewise, the following does not detect qualifier keys:
Option Explicit
Function OnClick(ByRef clickData)
Dim cmd
Set cmd = ClickData.func.Command
If ClickData.func.fromdrop Then
cmd.Addline "@keydown:none"
cmd.AddLine "@confirm ""no keys held down"""
cmd.Addline "@keydown:ctrl"
cmd.AddLine "@confirm ""ctrl held down"""
cmd.Run
Else
msgbox "regular click on button"
End If
End Function
There are separate drag & drop events for each qualifier key.
If you have the script directly in the event, it doesn't need to work out which qualifier is held down as it's implicit from the event it is attached to. (And a script added directly to, say, left double-click will not be run if you do ctrl + left double-click, since that's a separate event which runs its own script or command, if any is defined.)
If you have a script that adds a script command, and then want to set multiple events to run that command, with different behavior for different events, then the normal way to do it is to give the command arguments that allow each event to tell it how to behave.
(Qualifiers are not implicitly passed through from the drag & drop events as doing so causes problems with events that people want to do one thing, running commands that themselves check for qualifiers being held down and do a different thing if the key is down.)
Thanks for the thorough explanation Leo. I'm trying to consolidate some toolbar buttons but will need to go about it in a different way. The following will have to do for now:
Option Explicit
Function OnClick(ByRef clickData)
Dim cmd
Set cmd = ClickData.func.command
If ClickData.func.fromdrop Then
msgbox "drag-and-drop file/folder on button"
Else
If ClickData.func.qualifiers = "none" Then
msgbox "regular click on button, no qualifier keys"
ElseIf ClickData.func.qualifiers = "ctrl" Then
msgbox "regualr click on button, ctrl held down"
End If
End If
End Function