AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Changing the clipboard from within the OnClipboardChange

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
rousni



Joined: 23 Mar 2006
Posts: 41

PostPosted: Thu Nov 08, 2007 11:48 am    Post subject: Changing the clipboard from within the OnClipboardChange Reply with quote

Is there any way to change the clipboard from within the label named OnClipboardChange (especially by: Clipboard = %Clipboard%) without launching repeatedly the same label?
Thanks
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Thu Nov 08, 2007 7:51 pm    Post subject: Reply with quote

no - any change, even made by ahk, will launch the label again. you can always make logic involving a oneshot flag or other indicator to skip the second action.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Serenity



Joined: 08 Nov 2004
Posts: 1010

PostPosted: Sun Aug 31, 2008 12:47 am    Post subject: Reply with quote

engunneer wrote:
you can always make logic involving a oneshot flag or other indicator to skip the second action.


I tried this method but it has only reduced the number of loops, I still get duplicate entries in the clipboard and tooltip. Sad Is there is a better way to implement it?

Code:
#SingleInstance Force
#Persistent

OnClipboardChange:
; Thread, NoTimers, True ; helps reduce some of the repeats a little
; Critical ; makes it worse!!!
; SetBatchLines,-1 ; default 10ms works better

if c > 1 ; already running so ignore
{
   return
}
else
{
   ifwinactive, ahk_class MozillaUIWindowClass
   {
      c++
      wingetactivetitle, title
      title := RegExReplace( title, " -[\w ]+$" )    
                     
      if a_eventinfo = 1 ; text
      {
         if clipboard contains http:// ; deal with urls first
         {         
            if clipboard contains http://msdn.microsoft.com/en-us/library/
            {   
               if clipboard not contains `r`n
               {
                  link := clipboard
                  clipboard := title . "`n" . link
                  tooltip % title . "`n" . link
               }
            }
            
            if clipboard contains http://www.autohotkey.com/forum/viewtopic.php ; clean up forum urls
            {
               if clipboard not contains `r`n
               {
                  str := title  . "`n" . RegExReplace( clipboard, "\&\w(.*)" )
                  clipboard := str
                  tooltip % str
               }
            }
         }
      }
      c =
   }
}
settimer, tooltip, -1000      
return         
            
tooltip:
tooltip
return   

_________________
"Anything worth doing is worth doing slowly." - Mae West
Back to top
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 5887

PostPosted: Sun Aug 31, 2008 2:30 am    Post subject: Reply with quote

Serenity wrote:
Is there is a better way to implement it?


There might be a way with default method.. but here is a different method on how to Turn On/Off Clipboard monitoring.

Code:
Gui +LastFound
DllCall( "SetClipboardViewer", UInt,WinExist() ),  OnMessage( 0x308, "OnClipboardChange" )
Return                                                    ; // end of auto-execute section

OnClipboardChange() {                                              ; The Clipboard Monitor
  SetTimer, Mozilla, -1
; No return value required
}

Mozilla:
  IfWinNotActive, ahk_class MozillaUIWindowClass
    Return
  OnMessage( 0x308, "" )                                                        ; Turn Off
  WinGetActiveTitle, Title
  Title := RegExReplace( Title, "(- \w+ \w+$)" )   
  If Clipboard contains http://msdn.microsoft.com/en-us/library/
     If Clipboard not contains `r`n
        {
          link := Clipboard
          Clipboard := Title . "`n" . link
          Tooltip % Title . "`n" . link
          SetTimer, Tooltip, -2000
        }
  OnMessage( 0x308, "OnClipboardChange" )                                       ; Turn On
Return         
           
Tooltip:
 Tooltip
Return 


Smile

Edit: WM_DRAWCLIPBOARD = 0x308
_________________
SKAN - Suresh Kumar A N
Back to top
View user's profile Send private message
Serenity



Joined: 08 Nov 2004
Posts: 1010

PostPosted: Sun Aug 31, 2008 11:52 am    Post subject: Reply with quote

SKAN, Thank you!! I'm so happy now this is working. Very Happy
_________________
"Anything worth doing is worth doing slowly." - Mae West
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group