Jump to content

molitar

Members
  • Posts

    16
  • Joined

  • Last visited

Everything posted by molitar

  1. Thanks the new script worked great across 3 monitors.
  2. I'll test this when I get a chance been really busy at work right now due to some changes going on.
  3. I replaced these $aTSR[0] and $aTSR[1] with $DesktopWidth and $DesktopHeight. This way when get fixed version of script I can just remove the added 1921 to the x coordinates.
  4. Thanks for now I just added this to the mainscript.au3. Global $DesktopWidth = $aTSR[0] + 1921, $DesktopHeight = $aTSR[1] Global $DesktopWidth = $aTSR[0] + 1921, $DesktopHeight = $aTSR[1] This now allows me to scroll all the way across it does not affect the screen capture at all just affects the $block_gui. This will tide me over for now until you get a chance to clean it up. Thank you.
  5. ioa747 thank it's much cleaner but the cursor + is not working on multiple monitors so I added the wiki function for multiple monitors. At first it appeared to be working but I found a strange quirk when I moved the x coordinate past 2800 the + cursor disappeared and it showed as normal cursor but move it back under x 2800 coordinate and it goes back to the + cursor. x = 0 - 2800 (cursor appears correctly as the +) X = 2801 - 3060 (cursor reverts back to default mouse cursor so can't tell your still in capture mode though it is) #include-once #include <ScreenCapture.au3> #include <WindowsConstants.au3> #include <Clipboard.au3> #include <Misc.au3> ; #INDEX# ======================================================================================================================= ; Title .........: MoreSimpleCaptureTool (MSCT) ; AutoIt Version : 3.3.16.1 ; Language ......: English ; Description ...: Tool for capturing region of DeskTop ; Author(s) .....: ioa747 ; =============================================================================================================================== Global $aTSR = _GetTotalScreenResolution() ConsoleWrite("Total Screen Resolution" & @CRLF & "Width = " & $aTSR[0] & @CRLF & "Height = " & $aTSR[1]) ;Original code by Larry. ;Edited by BrettF Func _GetTotalScreenResolution() Local $aRet[2] Global Const $SM_VIRTUALWIDTH = 78 Global Const $SM_VIRTUALHEIGHT = 79 $VirtualDesktopWidth = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH) $aRet[0] = $VirtualDesktopWidth[0] $VirtualDesktopHeight = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALHEIGHT) $aRet[1] = $VirtualDesktopHeight[0] Return $aRet EndFunc ;==>_GetTotalScreenResolution Changed this line from ; make mouse block gui Local $block_gui = GUICreate("block_gui", @DesktopWidth, @DesktopHeight, -1, -1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) To this ; make mouse block gui Local $block_gui = GUICreate("block_gui", $aTSR[0], $aTSR[1], -1, -1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) #include-once #include <ScreenCapture.au3> #include <WindowsConstants.au3> #include <Clipboard.au3> #include <Misc.au3> ; #INDEX# ======================================================================================================================= ; Title .........: MoreSimpleCaptureTool (MSCT) ; AutoIt Version : 3.3.16.1 ; Language ......: English ; Description ...: Tool for capturing region of DeskTop ; Author(s) .....: ioa747 ; =============================================================================================================================== Global $aTSR = _GetTotalScreenResolution() ConsoleWrite("Total Screen Resolution" & @CRLF & "Width = " & $aTSR[0] & @CRLF & "Height = " & $aTSR[1]) ;Original code by Larry. ;Edited by BrettF Func _GetTotalScreenResolution() Local $aRet[2] Global Const $SM_VIRTUALWIDTH = 78 Global Const $SM_VIRTUALHEIGHT = 79 $VirtualDesktopWidth = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALWIDTH) $aRet[0] = $VirtualDesktopWidth[0] $VirtualDesktopHeight = DllCall("user32.dll", "int", "GetSystemMetrics", "int", $SM_VIRTUALHEIGHT) $aRet[1] = $VirtualDesktopHeight[0] Return $aRet EndFunc ;==>_GetTotalScreenResolution
  6. Thanks I see what you mean with the sleep for CPU Usage that maybe what is causing it because I'm on a work laptop and Sophos already uses a lot of CPU resources. Also the initial while loop did change a bit but not by much now that I put it into a form with a button control. I appreciate the tip.
  7. OK the simplecapturetool is a code from another user here so I am just calling the functions from. ; By FireFox, 2014 ; Version : 1.4 #include-once #include <WindowsConstants.au3> #include <Misc.au3> #include <WinAPI.au3> #include <ScreenCapture.au3> #include <ClipBoard.au3> #include <ColorConstants.au3> #include <Constants.au3> ; Settings Global $_fShowMousePos = True, $_fShowRectSize = True, $_fHideDesktop = False, $_fHideTaskBar = False, $giGDIPRef, $Capture = 0 Local $hGUICapt ;If HotKeySet("{HOME}", "ExampleClip") = 0 Then ; MsgBox($MB_SYSTEMMODAL, "", "Could not set the hotkey !") ; Exit 1 ;EndIf ;HotKeySet("^+{3}", "ExampleClip") ;for Windows under a MacBook lacking of a PrintScreen key (yes... me) ;While 1 ; Sleep(10000) ;10 sec ;WEnd Func ExampleClip() Global $iX1 = 0, $iY1 = 0, $iX2 = 0, $iY2 = 0 Local $hGUICapture = 0 Mark_Rect($hGUICapture, $iX1, $iY1, $iX2, $iY2) Local $hBitmap = _ScreenCapture_CaptureWnd("", $hGUICapture, $iX1, $iY1, $iX2, $iY2, False) Global $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) GUIDelete($hGUICapture) Local $fOpenCb = _ClipBoard_Open(0) If Not $fOpenCb Then MsgBox($MB_SYSTEMMODAL, "", "Could not open the clipboard !") Return False EndIf _ClipBoard_Empty() Local $hBitmap3 = _WinAPI_CopyImage($hBitmap, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG)) ;Save image to file ;_GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Capture.jpg") _WinAPI_DeleteObject($hBitmap) _ClipBoard_SetDataEx($hBitmap3, $CF_BITMAP) _ClipBoard_Close() _WinAPI_DeleteObject($hBitmap3) $Capture = 1 EndFunc ;==>ExampleClip Func Mark_Rect(ByRef $hGUICapture, ByRef $iX1, ByRef $iY1, ByRef $iX2, ByRef $iY2) Local $iX_Pos = 0, $iY_Pos = 0, $iTemp = 0, $iWidth = 0, $iHeight = 0 Local $hMask_1 = 0 Local $hWnd = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]") Local $aWgp = WinGetPos($hWnd) If $_fHideDesktop Then ControlHide($hWnd, "", "[CLASS:SysListView32; INSTANCE:1]") EndIf If $_fHideTaskBar Then WinSetState("[CLASS:Shell_TrayWnd]", "", @SW_HIDE) WinSetState("[CLASS:Button]", "", @SW_HIDE) EndIf Local $hBitmap = _ScreenCapture_Capture("", $aWgp[0], $aWgp[1], $aWgp[2], $aWgp[3]) Local $aSize[2] = [$aWgp[2], $aWgp[3]] $aWgp = 0 $hGUICapture = GUICreate("", $aSize[0], $aSize[1], 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_APPWINDOW, $WS_EX_TOPMOST)) GUISetCursor($IDC_CROSS, 1, $hGUICapture) If $giGDIPRef = 0 Then _GDIPlus_Startup() EndIf Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUICapture) Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) _WinAPI_DeleteObject($hBitmap) WinSetTrans($hGUICapture, "", 0) GUISetState(@SW_SHOWNOACTIVATE, $hGUICapture) _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage) If $giGDIPRef > 1 Then _GDIPlus_Shutdown() EndIf WinSetTrans($hGUICapture, "", 255) If $_fHideTaskBar Then WinSetState("[CLASS:Button]", "", @SW_SHOWNOACTIVATE) WinSetState("[CLASS:Shell_TrayWnd]", "", @SW_SHOWNOACTIVATE) EndIf If $_fHideDesktop Then ControlShow($hWnd, "", "[CLASS:SysListView32; INSTANCE:1]") EndIf Local $hGUIRect = GUICreate("", $aSize[0], $aSize[1], 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetBkColor($COLOR_BLACK) GUISetCursor($IDC_CROSS, 1, $hGUIRect) _GUICreateInvRect($hGUIRect, $aSize, $hMask_1, 0, 0, 1, 1) WinSetTrans($hGUIRect, "", 75) GUISetState(@SW_SHOWNOACTIVATE, $hGUIRect) Local $hUserDLL = DllOpen("user32.dll") Local $aMgp = 0 Local $fExitLoop = False ; Wait until mouse button pressed While Not _IsPressed("01", $hUserDLL) And Not $fExitLoop If $_fShowMousePos Then $aMgp = MouseGetPos() ToolTip("x: " & $aMgp[0] & ", y: " & $aMgp[1], _ $aMgp[0] + ($aMgp[0] > 100 ? -95 : 10), _ $aMgp[1] + ($aMgp[1] > 50 ? -35 : 10)) EndIf Sleep(10) If _IsPressed("1B", $hUserDLL) Then $fExitLoop = True WEnd If $_fShowMousePos Then ToolTip("") EndIf ; Get first mouse position $aMgp = MouseGetPos() $iX1 = $aMgp[0] $iY1 = $aMgp[1] ; Draw rectangle while mouse button pressed While _IsPressed("01", $hUserDLL) And Not $fExitLoop $aMgp = MouseGetPos() ; Set in correct order if required If $aMgp[0] < $iX1 Then $iX_Pos = $aMgp[0] $iWidth = $iX1 - $aMgp[0] Else $iX_Pos = $iX1 $iWidth = $aMgp[0] - $iX1 EndIf If $aMgp[1] < $iY1 Then $iY_Pos = $aMgp[1] $iHeight = $iY1 - $aMgp[1] Else $iY_Pos = $iY1 $iHeight = $aMgp[1] - $iY1 EndIf _GUICreateInvRect($hGUIRect, $aSize, $hMask_1, $iX_Pos, $iY_Pos, $iWidth, $iHeight) If $_fShowRectSize Then ToolTip("w: " & Abs($aMgp[0] - $iX1) & ", h: " & Abs($aMgp[1] - $iY1), _ $aMgp[0] + ((($aMgp[0] > $aSize[0] - 100 Or ($aMgp[0] - $iX1 < 0 And $aMgp[1] - $iY1 < 0)) And $aMgp[0] > 100) ? -95 : 10), _ $aMgp[1] + ((($aMgp[1] > $aSize[1] - 40 Or ($aMgp[0] - $iX1 < 0 And $aMgp[1] - $iY1 < 0)) And $aMgp[1] > 40) ? -35 : 10)) EndIf Sleep(10) If _IsPressed("1B", $hUserDLL) Then $fExitLoop = True WEnd If $_fShowRectSize Then ToolTip("") EndIf _WinAPI_DeleteObject($hMask_1) ; Get second mouse position $iX2 = $aMgp[0] $iY2 = $aMgp[1] ; Set in correct order if required If $iX2 < $iX1 Then $iTemp = $iX1 $iX1 = $iX2 $iX2 = $iTemp EndIf If $iY2 < $iY1 Then $iTemp = $iY1 $iY1 = $iY2 $iY2 = $iTemp EndIf GUIDelete($hGUIRect) DllClose($hUserDLL) EndFunc ;==>Mark_Rect Func _GUICreateInvRect($hWnd, $aSize, ByRef $hMask_1, $iX, $iY, $iW, $iH) Local $hMask_2 = 0, $hMask_3 = 0, $hMask_4 = 0 $hMask_1 = _WinAPI_CreateRectRgn(0, 0, $aSize[0], $iY) $hMask_2 = _WinAPI_CreateRectRgn(0, 0, $iX, $aSize[1]) $hMask_3 = _WinAPI_CreateRectRgn($iX + $iW, 0, $aSize[0], $aSize[1]) $hMask_4 = _WinAPI_CreateRectRgn(0, $iY + $iH, $aSize[0], $aSize[1]) _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_2, 2) _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_3, 2) _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_4, 2) _WinAPI_DeleteObject($hMask_2) _WinAPI_DeleteObject($hMask_3) _WinAPI_DeleteObject($hMask_4) _WinAPI_SetWindowRgn($hWnd, $hMask_1, 1) EndFunc ;==>_GUICreateInvRect The command for save as file to drive works fine. I want to load the captured image to the form so user knows that they actually captured what they wanted. So it's for confirmation. #include-once #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=c:\users\4477724\desktop\autoit\includes\main.kxf $Main = GUICreate("Main", 615, 437, 192, 124) Global $Button1 = GUICtrlCreateButton("Button1", 56, 72, 75, 25) Global $Button2 = GUICtrlCreateButton("Button2", 288, 72, 75, 25) Global $Pic1 = GUICtrlCreatePic("", 144, 72, 100, 100, BitOR($GUI_SS_DEFAULT_PIC,$WS_BORDER)) Global $Pic2 = GUICtrlCreatePic("", 376, 72, 100, 100, BitOR($GUI_SS_DEFAULT_PIC,$WS_BORDER)) $Label1 = GUICtrlCreateLabel("Screen Change Detector", 132, 2, 351, 40) GUICtrlSetFont(-1, 23, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x800000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #include "C:\Users\4477724\Desktop\AutoIT\includes\SimpleCaptureTool.au3" Local $X1 = 0, $Y1 = 0, $X2 = 0, $Y2 = 0 Global $hImage While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ExampleClip() ;Save image to file _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Capture1.jpg") Case $Button2 ExampleClip() ;Display Image in Picture Control GUICtrlSetImage($Pic1, $hImage) EndSwitch WEnd I know when I developed in Delphi coding if you made a change to the form you called a refresh to the control but I see nothing like that for AutoIT forms.
  8. #include-once #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=c:\users\4477724\desktop\autoit\includes\main.kxf $Main = GUICreate("Main", 615, 437, 192, 124) Global $Button1 = GUICtrlCreateButton("Button1", 56, 72, 75, 25) Global $Button2 = GUICtrlCreateButton("Button2", 288, 72, 75, 25) Global $Pic1 = GUICtrlCreatePic("", 144, 72, 100, 100, BitOR($GUI_SS_DEFAULT_PIC,$WS_BORDER)) Global $Pic2 = GUICtrlCreatePic("", 376, 72, 100, 100, BitOR($GUI_SS_DEFAULT_PIC,$WS_BORDER)) $Label1 = GUICtrlCreateLabel("Screen Change Detector", 132, 2, 351, 40) GUICtrlSetFont(-1, 23, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x800000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #include "C:\Users\4477724\Desktop\AutoIT\includes\SimpleCaptureTool.au3" Local $X1 = 0, $Y1 = 0, $X2 = 0, $Y2 = 0 Global $hImage While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ExampleClip() ;Save image to file _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Capture1.jpg") Case $Button2 ExampleClip() ;Display Image in Picture Control GUICtrlSetImage($Pic1, $hImage) <----- No Image displays on form. EndSwitch WEnd
  9. Yes that was for another button to save file to image but now I want a button to capture to the actual clipboard which works great as I can paste the image into paint but I want it to show the captured image on the form itself. The problem is that I can not figure out how to load it to the form control created with GUICtrlSetImage($Pic1, $hImage) If I try to create form again the form is already created so it's not going to load the image. This is where I am having trouble is how to load the image into the pic control and have it show the picture. The problem is it does not show any error so I expected that it did load but no image is displayed in the form. Still a blank image square.
  10. How do I load image to pic control on form? ExampleClip() ;Save image to file GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Capture1.jpg") $Pic1 = The image save to file created from the Global $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) works great but now how do I load this $hImage to the Pic control?
  11. OK I commented them out and than added a global variable to the SimpleCaptureToool.au3 so I know when I have captured the screenshot. include "C:\Users\4477724\Desktop\AutoIT\includes\SimpleCaptureTool.au3" Global $capture = 0 While $capture = 0 If HotKeySet("{HOME}", "Example") = 0 Then MsgBox($MB_SYSTEMMODAL, "", "Could not set the hotkey !") Exit 1 EndIf If $capture = 1 Then ConsoleWrite("Global Var coordinates: " & $iX1 & ", " & $iY1 & ", " & $iX2 & ", " & $iY2);verify I got the coordinates $capture = 0 EndIf WEnd Sometimes when I capture it will not let me capture again. Sometimes I get 1, 2 or 3 captures than the process terminates. Console Output: Global Var coordinates: 2107, 231, 2394, 363 +>02:02:10 AutoIt3.exe ended.rc:0 +>02:02:10 AutoIt3Wrapper Finished. >Exit code: 0 Time: 8.337 As you can see it successfully captured one time the second time it finished the entire process exiting it.
  12. In main script I am using an include that has another function. The function is called and runs fine but it stops inside the include. It is a script by Firefox used to do a simple screen capture to clipboard. The problem is the call works and I get the screen capture in the clipboard but it does not return to the main script to continue. What am I doing wrong? I know I could put it into one large script but I am trying to learn how to call functions from an include and keep the processes separate for easier coding and debugging. main.au3 #include "C:\Users\4477724\Desktop\AutoIT\includes\SimpleCaptureTool.au3" If HotKeySet("{HOME}", "Example") = 0 Then MsgBox($MB_SYSTEMMODAL, "", "Could not set the hotkey !") Exit 1 EndIf ConsoleWrite("Global Var coordinates: " & $iX1 & ", " & $iY1 & ", " & $iX2 & ", " & $iY2) SimpleCaptureTool ; By FireFox, 2014 ; Version : 1.4 #include <WindowsConstants.au3> #include <Misc.au3> #include <WinAPI.au3> #include <ScreenCapture.au3> #include <ClipBoard.au3> #include <ColorConstants.au3> #include <Constants.au3> ; Settings Global $_fShowMousePos = True, $_fShowRectSize = True, $_fHideDesktop = False, $_fHideTaskBar = False, $giGDIPRef If HotKeySet("{HOME}", "Example") = 0 Then MsgBox($MB_SYSTEMMODAL, "", "Could not set the hotkey !") Exit 1 EndIf HotKeySet("^+{3}", "Example") ;for Windows under a MacBook lacking of a PrintScreen key (yes... me) While 1 Sleep(10000) ;10 sec WEnd Func Example() Global $iX1 = 0, $iY1 = 0, $iX2 = 0, $iY2 = 0 Local $hGUICapture = 0 Mark_Rect($hGUICapture, $iX1, $iY1, $iX2, $iY2) Local $hBitmap = _ScreenCapture_CaptureWnd("", $hGUICapture, $iX1, $iY1, $iX2, $iY2, False) GUIDelete($hGUICapture) Local $fOpenCb = _ClipBoard_Open(0) If Not $fOpenCb Then MsgBox($MB_SYSTEMMODAL, "", "Could not open the clipboard !") Return False EndIf _ClipBoard_Empty() Local $hBitmap3 = _WinAPI_CopyImage($hBitmap, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG)) _WinAPI_DeleteObject($hBitmap) _ClipBoard_SetDataEx($hBitmap3, $CF_BITMAP) _ClipBoard_Close() _WinAPI_DeleteObject($hBitmap3) EndFunc ;==>Example Func Mark_Rect(ByRef $hGUICapture, ByRef $iX1, ByRef $iY1, ByRef $iX2, ByRef $iY2) Local $iX_Pos = 0, $iY_Pos = 0, $iTemp = 0, $iWidth = 0, $iHeight = 0 Local $hMask_1 = 0 Local $hWnd = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]") Local $aWgp = WinGetPos($hWnd) If $_fHideDesktop Then ControlHide($hWnd, "", "[CLASS:SysListView32; INSTANCE:1]") EndIf If $_fHideTaskBar Then WinSetState("[CLASS:Shell_TrayWnd]", "", @SW_HIDE) WinSetState("[CLASS:Button]", "", @SW_HIDE) EndIf Local $hBitmap = _ScreenCapture_Capture("", $aWgp[0], $aWgp[1], $aWgp[2], $aWgp[3]) Local $aSize[2] = [$aWgp[2], $aWgp[3]] $aWgp = 0 $hGUICapture = GUICreate("", $aSize[0], $aSize[1], 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_APPWINDOW, $WS_EX_TOPMOST)) GUISetCursor($IDC_CROSS, 1, $hGUICapture) If $giGDIPRef = 0 Then _GDIPlus_Startup() EndIf Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUICapture) Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap) _WinAPI_DeleteObject($hBitmap) WinSetTrans($hGUICapture, "", 0) GUISetState(@SW_SHOWNOACTIVATE, $hGUICapture) _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage) If $giGDIPRef > 1 Then _GDIPlus_Shutdown() EndIf WinSetTrans($hGUICapture, "", 255) If $_fHideTaskBar Then WinSetState("[CLASS:Button]", "", @SW_SHOWNOACTIVATE) WinSetState("[CLASS:Shell_TrayWnd]", "", @SW_SHOWNOACTIVATE) EndIf If $_fHideDesktop Then ControlShow($hWnd, "", "[CLASS:SysListView32; INSTANCE:1]") EndIf Local $hGUIRect = GUICreate("", $aSize[0], $aSize[1], 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetBkColor($COLOR_BLACK) GUISetCursor($IDC_CROSS, 1, $hGUIRect) _GUICreateInvRect($hGUIRect, $aSize, $hMask_1, 0, 0, 1, 1) WinSetTrans($hGUIRect, "", 75) GUISetState(@SW_SHOWNOACTIVATE, $hGUIRect) Local $hUserDLL = DllOpen("user32.dll") Local $aMgp = 0 Local $fExitLoop = False ; Wait until mouse button pressed While Not _IsPressed("01", $hUserDLL) And Not $fExitLoop If $_fShowMousePos Then $aMgp = MouseGetPos() ToolTip("x: " & $aMgp[0] & ", y: " & $aMgp[1], _ $aMgp[0] + ($aMgp[0] > 100 ? -95 : 10), _ $aMgp[1] + ($aMgp[1] > 50 ? -35 : 10)) EndIf Sleep(10) If _IsPressed("1B", $hUserDLL) Then $fExitLoop = True WEnd If $_fShowMousePos Then ToolTip("") EndIf ; Get first mouse position $aMgp = MouseGetPos() $iX1 = $aMgp[0] $iY1 = $aMgp[1] ; Draw rectangle while mouse button pressed While _IsPressed("01", $hUserDLL) And Not $fExitLoop $aMgp = MouseGetPos() ; Set in correct order if required If $aMgp[0] < $iX1 Then $iX_Pos = $aMgp[0] $iWidth = $iX1 - $aMgp[0] Else $iX_Pos = $iX1 $iWidth = $aMgp[0] - $iX1 EndIf If $aMgp[1] < $iY1 Then $iY_Pos = $aMgp[1] $iHeight = $iY1 - $aMgp[1] Else $iY_Pos = $iY1 $iHeight = $aMgp[1] - $iY1 EndIf _GUICreateInvRect($hGUIRect, $aSize, $hMask_1, $iX_Pos, $iY_Pos, $iWidth, $iHeight) If $_fShowRectSize Then ToolTip("w: " & Abs($aMgp[0] - $iX1) & ", h: " & Abs($aMgp[1] - $iY1), _ $aMgp[0] + ((($aMgp[0] > $aSize[0] - 100 Or ($aMgp[0] - $iX1 < 0 And $aMgp[1] - $iY1 < 0)) And $aMgp[0] > 100) ? -95 : 10), _ $aMgp[1] + ((($aMgp[1] > $aSize[1] - 40 Or ($aMgp[0] - $iX1 < 0 And $aMgp[1] - $iY1 < 0)) And $aMgp[1] > 40) ? -35 : 10)) EndIf Sleep(10) If _IsPressed("1B", $hUserDLL) Then $fExitLoop = True WEnd If $_fShowRectSize Then ToolTip("") EndIf _WinAPI_DeleteObject($hMask_1) ; Get second mouse position $iX2 = $aMgp[0] $iY2 = $aMgp[1] ; Set in correct order if required If $iX2 < $iX1 Then $iTemp = $iX1 $iX1 = $iX2 $iX2 = $iTemp EndIf If $iY2 < $iY1 Then $iTemp = $iY1 $iY1 = $iY2 $iY2 = $iTemp EndIf GUIDelete($hGUIRect) DllClose($hUserDLL) EndFunc ;==>Mark_Rect Func _GUICreateInvRect($hWnd, $aSize, ByRef $hMask_1, $iX, $iY, $iW, $iH) Local $hMask_2 = 0, $hMask_3 = 0, $hMask_4 = 0 $hMask_1 = _WinAPI_CreateRectRgn(0, 0, $aSize[0], $iY) $hMask_2 = _WinAPI_CreateRectRgn(0, 0, $iX, $aSize[1]) $hMask_3 = _WinAPI_CreateRectRgn($iX + $iW, 0, $aSize[0], $aSize[1]) $hMask_4 = _WinAPI_CreateRectRgn(0, $iY + $iH, $aSize[0], $aSize[1]) _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_2, 2) _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_3, 2) _WinAPI_CombineRgn($hMask_1, $hMask_1, $hMask_4, 2) _WinAPI_DeleteObject($hMask_2) _WinAPI_DeleteObject($hMask_3) _WinAPI_DeleteObject($hMask_4) _WinAPI_SetWindowRgn($hWnd, $hMask_1, 1) EndFunc ;==>_GUICreateInvRect
  13. Thanks this worked great. The code is clean and easy to understand and I have values for all 3 buttons. The only question I have is where did you get the value 620 to know that is what is returned.
  14. OK that works for ControlClick but is it possible to get the value of button pressed the other way around. Detect what button is clicked on by the user? Now I have a problem with this code I have to keep using the Stop Script as it does not properly terminate it seems. #include <MsgBoxConstants.au3> Run("notepad.exe") WinWaitActive("Untitled - Notepad") Send("Cool IT Help Tutorial") WinClose("*Untitled - Notepad") WinWaitActive("Notepad", "Save") ; variable for name of button $id = "&Save" $res = ControlClick("Notepad", "", $id) If $res Then MsgBox(0, "Notepad", "The " & $id & " button was pressed", 3) Else ;error EndIf If WinWaitActive("Save As", "Text") Then Send("C:\Users\xxxxxx\Desktop\AutoIT\MyFirstFiletxt") WinWaitActive("Save As", "Save") Send("{ENTER}") WinWaitActive("MyFirstFile.txt - Notepad") WinClose("MyFirstFile.txt - Notepad") EndIf Why does this script hang and not close correctly?
  15. OK found this works. WinWaitActive("Notepad", "Save") ControlClick("Notepad", "", "Do&n't Save") Now is it possible to get the result of which button was pressed in this window? The windowinfo below. I can't figure out how to get result of which button was pressed and than show in a message box. If I can get it to show in message box than I can use it for if statements.
  16. So here is the tutorial I used. Run("notepad.exe") WinWaitActive("Untitled - Notepad") Send("Cool IT Help Tutorial") WinClose("*Untitled - Notepad") WinWaitActive("Notepad", "Save") Send("{ENTER}") WinWaitActive("Save As", "Text") Send("C:\Users\4477724\Desktop\AutoIT\MyFirstFiletxt") WinWaitActive("Save As", "Save") Send("{ENTER}") WinWaitActive("MyFirstFile.txt - Notepad") WinClose("MyFirstFile.txt - Notepad") So I tried to change the line that says WinWaitActive("Notepad", "Save") to the one below. WinWaitActive("Notepad", "Don't Save") Than I tried to use the text from the Window Info instead still did not work. WinWaitActive("Notepad", "Do&n't Save") So it appears that the ONLY reason the save is working is because that is already the default button and that line of code is not actually selecting the button at all. So how do I actually properly select the button?
×
×
  • Create New...