Jump to content

selectively apply click and drag


Recommended Posts

Hi all.

I`ve been playing around with the below function with the intention of having it apply to any window which is active. Presently it is set up to click and drag the active window except when the window is maximized; the cursor is not an arrow; shift is pressed or certain windows are active. Works well and am generally happy.

I have two problems I can`t resolve

1) Double clicks are no longer registering

2) I cannot isolate scrollbars in order to exclude them.

Can anyone help?

Picea

;===============================================================================
;
; Description:    Moves any Window by Left Mouse "Click & Drag"
; Syntax:          _WinMove($hWnd) or  _WinMove($s_Title)
; Parameter(s):  $s_hWnd = as returned by GUICreate()
;                  $s_Title = title of window to be moved
; Requirement(s):   None
; Return Value(s):  On Success - Repositions the Window
;                  On Failure - Returns ""
; Author(s):        Valuater,  Valuater [at] aol [.com], Inspired by Martin
;
;===============================================================================
Func _WinMove()
    $hWnd=WinGetTitle("","")
    $pow=WinGetState($hWnd,"")
    $po=MouseGetCursor()

    If $hWnd = "taskbar" or $hWnd = "Program Manager" or $po<>2 or BitAnd($pow, 32) Then Return
    if _IsPressed("10", $dll) Then Return
    Local $a_R = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", '0x1')
    If @error Or BitAND($a_R[0], 0x8000) <> 0x8000 Then Return
    Local $a = WinGetPos($hWnd), $b = MouseGetPos()
    If $b[0] < $a[0] Or $b[1] < $a[1] Or $b[0] > $a[2] + $a[0] Or $b[1] > $a[3] + $a[1] Then Return
    While WinActive($hWnd)
        Local $c = MouseGetPos()
        WinMove($hWnd, '', $a[0] + $c[0] - $b[0], $a[1] + $c[1] - $b[1])
        $a_R = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", '0x1')
        If @error Or BitAND($a_R[0], 0x8000) <> 0x8000 Then Return
    WEnd
EndFunc ;==>_WinMove
Edited by picea892
Link to comment
Share on other sites

Perhaps I made some progress on this

#Include <Misc.au3>
#Include <WinAPI.au3>
global $dll = DllOpen("user32.dll"),$excludedblclick
While 1
if  $excludedblclick<4 and _IsPressed("01", $dll) then
    $excludedblclick=$excludedblclick+1
Elseif $excludedblclick>3 and _IsPressed("01", $dll) and not WinExists("Drag") and not _IsPressed("10", $dll) Then
 _WinMove()
elseif not _IsPressed("01", $dll) then
    $excludedblclick=0
EndIf
sleep(100)  
WEnd

;===============================================================================
;
; Description:    Moves any Window by Left Mouse "Click & Drag"
; Syntax:          _WinMove($hWnd) or  _WinMove($s_Title)
; Parameter(s):  $s_hWnd = as returned by GUICreate()
;                  $s_Title = title of window to be moved
; Requirement(s):   None
; Return Value(s):  On Success - Repositions the Window
;                  On Failure - Returns ""
; Author(s):        Valuater,  Valuater [at] aol [.com], Inspired by Martin
; Modified:         Picea892
;
;===============================================================================
Func _WinMove()
    $hWnd=WinGetTitle("","")
    $pow=WinGetState($hWnd,"")
    $po=MouseGetCursor()
    $tRect=_WinAPI_GetWindowRect(WinGetHandle($hwnd))
    $mouseloc=MouseGetPos()
    If $mouseloc[1]< DllStructGetData($tRect, 1)+25 _ 
    or $mouseloc[1]> DllStructGetData($tRect, 4)-50 _
    or $mouseloc[0]> DllStructGetData($tRect, 3)-25 or $hWnd = "Program Manager" _ 
    or $po<>2 or BitAnd($pow, 32) Then Return
    
    Local $a_R = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", '0x1')
    If @error Or BitAND($a_R[0], 0x8000) <> 0x8000 Then Return
    Local $a = WinGetPos($hWnd), $b = MouseGetPos()
    If $b[0] < $a[0] Or $b[1] < $a[1] Or $b[0] > $a[2] + $a[0] Or $b[1] > $a[3] + $a[1] Then Return
    While WinActive($hWnd)
        Local $c = MouseGetPos()
        WinMove($hWnd, '', $a[0] + $c[0] - $b[0], $a[1] + $c[1] - $b[1])
        $a_R = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", '0x1')
        If @error Or BitAND($a_R[0], 0x8000) <> 0x8000 Then Return
    WEnd
EndFunc  ;==>_WinMove
Link to comment
Share on other sites

Is there someone who can help me? I'm so close..... I just can't figure out how to exclude doubleclicks. I can have a timer delay (only check every 700ms) but I don't want to do that. How can I run this script and still use my doubleclick?

CODE
#Include <Misc.au3>

#Include <WinAPI.au3>

#include <Constants.au3>

#include <WindowsConstants.au3>

global $dll = DllOpen("user32.dll")

While 1

sleep(500)

movedecision()

WEnd

func movedecision()

local $excludemove="|Internet Explorer_Server|SysListView32|SysTreeView32|Scintilla|Edit|OperaWindowClass|ComboLBox|ComboBox|_WwG|

ScrollBar|EXCEL<|EXCEL7|SUPERGRID|RichEdit20W|VbaWindow|"

$po=MouseGetCursor()

$pos = _WinAPI_GetMousePos()

$point=_WinAPI_WindowFromPoint($pos)

;$hWnd=_WinAPI_GetParent($point)

$hWnd =WinGetHandle("","")

$titled=WinGetTitle($hWnd)

$contrlhandled=ControlGetHandle($hWnd,'',$point)

Dim $iStyle = _WinAPI_GetWindowLong($contrlhandled, $GWL_STYLE)

$tRect=_WinAPI_GetWindowRect($hWnd)

$mouseloc=MouseGetPos()

$pow=WinGetState($hWnd,"")

;ToolTip(_WinAPI_GetClassName($point))

if _IsPressed("01", $dll) and _IsPressed("10", $dll)then movewin($hWnd) ;bypass

If _IsPressed("02", $dll) and _IsPressed("10", $dll)then rgtclwin($hWnd)

If Not StringInStr($excludemove, "|" & _WinAPI_GetClassName($point) & "|") and $po=2 and not BitAnd($pow, 32) and not WinExists("Drag") Then

if $mouseloc[0]> DllStructGetData($tRect, 2)+25 or $titled="Program Manager" then

if _IsPressed("01", $dll) and not _IsPressed("02", $dll) Then movewin($hWnd)

if _IsPressed("02", $dll) and Not _IsPressed("01", $dll) Then rgtclwin($hWnd)

EndIf

EndIf

EndFunc

func movewin($hWnd)

Local $MousePos, $WinPos, $PosDiff[2]

While 1

$MousePos = MouseGetPos ()

$WinPos = WinGetPos ("","")

$PosDiff[0] = $WinPos[0] - $MousePos[0]

$PosDiff[1] = $WinPos[1] - $MousePos[1]

While _IsPressed ("01", $dll)

$MousePos = MouseGetPos ()

WinMove ("", "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1])

$WinPos = WinGetPos ("","")

Sleep (10)

if _IsPressed ("02", $dll) then

WinSetState($hWnd,"",@SW_MINIMIZE)

sleep(200)

return

EndIf

WEnd

ExitLoop

Sleep (10)

WEnd

EndFunc

func rgtclwin($hWnd)

While _IsPressed ("02", $dll)

Sleep (10)

if _IsPressed ("01", $dll) then

$lk=WinGetState($hWnd)

If BitAnd($lk, 16) Then

WinSetState($hWnd,"",@SW_MAXIMIZE)

elseIf BitAnd($lk, 32) Then

WinSetState($hWnd,"",@SW_RESTORE)

EndIf

sleep(200)

return

EndIf

WEnd

EndFunc

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...