Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to detect clipboard copy
#1
How can QM detect when something has been copied to the clipboard?
#2
Where you will use it? Should it be like a trigger, or like a wait command in macro?

To press Ctrl+C and wait until clipboard is populated, use getsel function of str.

str s
s.getsel ;;presses Ctrl+C, waits until clipboard is populated, and stores the text into s
#3
Yes, I think I can simply trigger on Ctrl+C, use .getsel. But a trigger that used the clipboard chain would also work when copying via menu selection, toolbar button, etc.
#4
I'm processing copying in other applications triggered on Cc:

Code:
Copy      Help
;;keep stack of recently copied text

int+ cc_next    ;; global variable to hold last copied position
str+ cc_last    ;; last string copied
def MAX_CLIPBOARD 30

;;retrieve clipboard contents
str s.getsel
s.trim
if s.len > 3 and s.len < 30000 and s <> cc_last
,;;determine next filename to store text in
,cc_next + 1
,if cc_next > MAX_CLIPBOARD
,,cc_next = 1

,;;write to file
,s.setfile(ClipFilename(cc_next))

,cc_last = s
,
key Cc

This results in several applications on my computer reporting the inability to access the clipboard every other time Ctrl+C is pressed. Is there a better way? A true trigger on the WM_DRAWCLIPBOARD notification would be preferable since it would also handle copy via the mouse, cut, copy with another keyboard shortcut, etc. Thanks.
#5
I don't know about how to do this in qm but i use yankee clipper to keep a clipboard history.

http://www.intelexual.com/products/index.aspx
An old blog on QM coding and automation.

The Macro Hook
#6
I had been using ClipX http://bluemars.org/clipx/ which works great except for a couple annoyances, and I'm trying to reduce the # of apps I need installed, so I rewrote it in QM in about 60 lines of code. But the problem/limitation above is annoying.
#7
getsel also presses Ctrl+C. Instead of

getsel
...
key Cc

Try

opt clip 1 ;;don't restore clipboard text
getsel
;and no key Cc

------

Quote:A true trigger on the WM_DRAWCLIPBOARD notification would be preferable

You can create this trigger in QM. It is possible to add user-defined triggers to Properties.
#8
Gintaras Wrote:getsel also presses Ctrl+C. Instead of

getsel
...
key Cc

Try

opt clip 1 ;;don't restore clipboard text
getsel
;and no key Cc
That didn't help, but checking 'When released' on the hotkey trigger did.

Quote:You can create this trigger in QM. It is possible to add user-defined triggers to Properties.
Is there a sample that triggers on a Windows notification?
#9
Two samples are in c:\program files\quick macros 2\installed files\samples2.qml. Import it, or part of it.

1. Power management triggers. It is simpler (very simple for programmers) but does not add the trigger to Properties.

2. Keyboard triggers 2. Adds to Properties.

If you want to add to Properties, also read 'Triggers: user-defined' topic in Help.
#10
I created a function DrawClipboard triggered on QM file loaded:

Code:
Copy      Help
;\
function# hWnd message wParam lParam
if(hWnd) goto messages

hWnd=CreateWindowEx(0 +32770 0 0 0 0 0 0 0 0 _hinst 0) ;;this hidden window will receive messages
int+ __drawclip_wndproc=SetWindowLong(hWnd GWL_WNDPROC &DrawClipboard) ;;subclass
MessageLoop ;;retrieve messages; run until PostQuitMessage
ret

;messages
sel message
,case WM_DRAWCLIPBOARD
,out "draw clipboard"
;,mac("Process Clipboard")
,
,case WM_CLOSE if(wParam) DestroyWindow(hWnd)
,
,case WM_DESTROY
,PostQuitMessage 0
,
ret CallWindowProc(__drawclip_wndproc hWnd message wParam lParam)

I don't get any output when copying. Is it running? How do I tell? Thanks.
#11
Every window does not receive WM_DRAWCLIPBOARD. Call SetClipboardViewer to register the window. Also needed some more management code. See 'Using the Clipboard' in the MSDN Library.

Running threads are displayed in the Threads dialog. It is in Tools menu and in tray menu.
#12
This is too complicated for me.

Can you help us with this user-defined trigger?
#13
Function dlg_clipboard_viewer
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str rea3
if(!ShowDialog("dlg_clipboard_viewer" &dlg_clipboard_viewer &controls)) ret

;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 223 135 "QM Clipboard Viewer"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;3 RichEdit20A 0x54233044 0x200 0 0 224 114 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030008 "*" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,int-- t_hwndnext
,t_hwndnext=SetClipboardViewer(hDlg)
,SetTimer hDlg 23 1000 0
,
,case WM_DESTROY
,ChangeClipboardChain hDlg t_hwndnext
,
,case WM_CHANGECBCHAIN
,if(wParam=t_hwndnext) t_hwndnext=lParam
,else if(t_hwndnext) SendMessage t_hwndnext message wParam lParam
,
,case WM_TIMER
,sel wParam
,,case 23 ;;auto restore if another viewer did not remove itself correctly
,,if(!GetClipboardViewer) t_hwndnext=SetClipboardViewer(hDlg)
,
,case WM_DRAWCLIPBOARD ;;clipboard contents changed
,str s.getclip; err
,s.setwintext(id(3 hDlg))
,SendMessage t_hwndnext message wParam lParam
,
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

err+
,ChangeClipboardChain hDlg t_hwndnext
,end _error
#14
Quote:You can create this trigger in QM. It is possible to add user-defined triggers to Properties.

Thanks, but How can I add this function (Activate a macro based on the contents of the clipboard) to QM triggers like 'Shell menu' or 'Keyboard 2'?
#15
Clipboard copy triggers
#16
Thanks to you.

I think I will never be able to create functions such as yours ...

Note: You can add this function to a new QM version. (it can be very useful).
#17
Just thought how useful this feature would be - and here it is!  Smile
This discussion ended in 2009 - has anything happened since then or is that still the suggested approach?
#18
A newer Windows version added message WM_CLIPBOARDUPDATE. Now it is recommended.

https://www.quickmacros.com/forum/showth...1#pid34251


Forum Jump:


Users browsing this thread: 3 Guest(s)