Jump to content

Recommended Posts

Posted (edited)

been messing with this for a while now trying to get leftclick to disable clicking on windows, but at the same time able to activate functions. Just a simple screenshot program... I know HotKeySet disables the key while in use. Trying to mimic it with _IsPressed though, is another story...

#include <ScreenCapture.au3>
#include <Misc.au3>

;click upper left to lower right

HotKeySet("{ESC}", "End")

Global $Mpos1_x
Global $Mpos1_y
Global $Mpos2_x
Global $Mpos2_y
Global $check = 0

FindCoords()

Func FindCoords()

While 1

If $check = 0 Then
    Get1()
EndIf
If $check = 1 Then
    Get2()
EndIf

WEnd
EndFunc

Func Get1()
    If _IsPressed("01") Then
        $check = 1
            $Mpos1 = MouseGetPos()
            $Mpos1_x = $Mpos1[0]
            $Mpos1_y = $Mpos1[1]
        Sleep(150)
    EndIf
EndFunc

Func Get2()
    If _IsPressed("01") Then
        $check = 3
            $Mpos2 = MouseGetPos()
            $Mpos2_x = $Mpos2[0]
            $Mpos2_y = $Mpos2[1]
        Sleep(150)
        Capture()
    EndIf
EndFunc

Func Capture()
    Local $randomness = Random(0, 999999)
    $randomnumber = Round($randomness)
        _ScreenCapture_Capture("V:\location\"&$randomnumber&".jpg", $Mpos1_x, $Mpos1_y, $Mpos2_x, $Mpos2_y)
    Exit
EndFunc

Func End()
    Exit
EndFunc

 

Edited by HankHell
double paste
Posted (edited)

Or use a combination key + mouse hook

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <ScreenCapture.au3>

Global $hHook, $hFunc, $pFunc, $hMod
Global $check, $pos1, $pos2

HotKeySet('{ESC}', '_Close')

$hFunc = DllCallbackRegister('_MouseProc', 'lresult', 'int;int;int')
$pFunc = DllCallbackGetPtr($hFunc)
$hMod = _WinAPI_GetModuleHandle(0)
$hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, $pFunc, $hMod)

While 1
      If $check = 2 Then 
        $check = 0
       ; Return MsgBox(4096, "", $pos1[0]&"x"&$pos1[1]&@crlf &$pos2[0]&"x"&$pos2[1])
       _ScreenCapture_Capture(@scriptdir&"\test.jpg", $pos1[0], $pos1[1], $pos2[0], $pos2[1])
       ShellExecute(@scriptdir&"\test.jpg")
    EndIf
WEnd


Func _MouseProc($iCode, $iwParam, $ilParam)
   If $iCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
   If _IsPressed("10") Then  ; SHIFT
      Switch $iwParam
        Case $WM_LBUTTONUP
            If $check = 0 Then
                 $pos1 = MouseGetPos()
                 $check = 1
            ElseIf $check = 1 Then
                 $pos2 = MouseGetPos()
                 $check = 2
            EndIf
        Case $WM_RBUTTONDOWN ; reset at any time
            $check = 0
      EndSwitch
      Return 1
   EndIf
   Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam)
EndFunc   ;==>_MouseProc

Func _Close()
    _WinAPI_UnhookWindowsHookEx($hHook)
    DllCallbackFree($hHook)
    Exit
EndFunc   ;==>_Close

 

Edited by mikell
comment

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
  • Recently Browsing   0 members

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