Using v2 I used the OnClipboardChange to call a function to copy the clipboard contents to a variable, then emptied the clipboard, then copied the variable back to the clipboard. Fortunately this now made the contents visible when using the clipboard history in VB6.
But I found that if I pasted the non-last entry from the clipboard history (in other programs as well, not just VB6) that it seemed to trigger the OnClipboardChange event also and I now had the pasted entry duplicated in the top spot on the clipboard history viewer. (Perhaps Win10 does an internal copy to the 'classic' clipboard from the 'newer with history' clipboard). Looking into this further I looked at the WM_CLIPBOARDUPDATE (0x031D) msg with VS Spy++ (this msg is also received by AHK if the OnClipboardChange function is used) and found that with a normal copy operation the wParam = 6 and with a Win10 clipboard history paste of any non-last entry the wParam = 8. All this even though the MS docs read that the wParam is not used and must be zero.
So I have the following code which seems to get around the issues outlined above, and am interested in any comments.
Code: Select all
#Requires AutoHotkey v2.0-a
OnClipboardChange ClpBrd_Change, 1
OnMessage 0x031D, wm_ClpBrdUpdate ; WM_ClipboardUpdate = 0x031D wParam=6 with classic copy, wParam=8 with paste from Win10 Clipboard History of non-last entry
wm_ClpBrdUpdate(wParam, lParam, msg, hWnd) {
global ClpBrdUpdate := wParam
}
ClpBrd_Change(iType) {
; workaround for VB6 Clipboard bug - entries present but no preview on Win10 Clipboard history
; this function gets called when Class IDEOwner (VB6) is active
; and clipboard contents change also when pasting from Win10 Clipboard History
; therefore deactivate OnClipboardChange when Clipboard History appears - see ShellHookMessage OR
; use ClpBrdUpdate (= wParam) to distinguish between classic copy (=6) or Win10 Clip history paste of non-last entry (8)
global ClpBrdUpdate
if ClpBrdUpdate = 6 and iType = 1 and WinActive("ahk_class wndclass_desked_gsk") ; code pane Class for VB6 (and VBA7)
{
OnClipboardChange ClpBrd_Change, 0 ; turn off so that function is not called recursively
cb .= A_Clipboard ; save text content of Clipboard. Compare with ClipboardAll
Sleep 20
A_Clipboard := "" ; Empty Clipboard of recent VB6 copy because they don't show in Clipboard history
Sleep 20
A_Clipboard := cb ; copy saved contents back to Clipboard from AHK which will show in Clipboard history
Sleep 20
ToolTip cb ; to indicate this function is active
OnClipboardChange ClpBrd_Change, 1 ; turn back on
}
; Tooltip "ClpBrd changed"
}