Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 07, 2016, 08:28:12 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: AutoHotKey: How to drag & drop _safely_  (Read 5017 times)

nosh

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,426
    • View Profile
    • Donate to Member
AutoHotKey: How to drag & drop _safely_
« on: April 18, 2008, 04:29:54 AM »
I've written a script to combine two of my favorite programs, AvaFind & Xplorer². The script selects the results (files) from Avafind and drops them to an X² scrap pane. It's running fine but since this is a drag-drop operation I would like to eliminate any risk of dragging the wrong source (and/or) to the wrong target. Both apps are positioned by the script before the drag-drop but if one doesn't load due to some errors or a third app gets focus at the wrong time the results could be potentially disastrous. 8)

And ideas how to eliminate this risk? Just ideas without code sample would be very welcome too.


Quote
F11::
; AvaFind small thumb preview in X2 scrap pane
IfWinActive ,ahk_class AUI40WndClass
{   WinActivate ,ahk_class AUI40WndClass
            WinMove 0,0
        ; preview pane running
   IfWinExist, scrap² - Avafind Preview.cida
   {       WinActivate, scrap² - Avafind Preview.cida
         WinMove, 1281,0
         WinMaximize
         Sleep, 300         
         Send {Alt}vpt
         Sleep, 300
         Send {Alt}vau
         WinActivate ,ahk_class AUI40WndClass
         Sleep, 300      
         Send ^a
         MouseClickDrag, L, 600, 130, 2470, 900
         WinActivate, scrap² - Avafind Preview.cida
         Sleep, 1000
         Send ^r         
         return
   }      
   ; preview pane not started yet
            else
   {
      Run D:\Xplorer2\Avafind Preview.cida, , Max
      WinWait, scrap² - Avafind Preview.cida
      WinActivate, scrap² - Avafind Preview.cida
      WinMove, 1281,0
      Sleep, 300
      Send ^o
      Sleep, 300
      Send {Alt}vpt
      Sleep, 300
      Send {Alt}vad
      Sleep, 300      
      Send {Alt}vvr{{}pictures{}}{Enter}
      WinActivate ,ahk_class AUI40WndClass
      Sleep, 300            
      Send ^a
      MouseClickDrag, L, 600, 130, 2470, 900
      WinActivate, scrap² - Avafind Preview.cida
      Send ^r
      return
   }
}

; not Avafind - normal behavior
else
{   Send {F11}
   return
}

wr975

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 369
    • View Profile
    • Donate to Member
Re: AutoHotKey: How to drag & drop _safely_
« Reply #1 on: April 19, 2008, 04:32:55 PM »
Two ideas:

Set the window AlwaysOnTop (WinSet, AlwaysonTop, On, ...) to avoid another application stealing focus

Use IfWin(Not)Active to check if everything is OK, else goto error & abort.

nosh

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,426
    • View Profile
    • Donate to Member
Re: AutoHotKey: How to drag & drop _safely_
« Reply #2 on: April 19, 2008, 09:52:18 PM »
Will implement them both. Thanks!