mazz3d

Firefox with random window size

8 posts in this topic

hello  everyone,

I'm new with AutoIT and just looking for a way to open Firefox with random window size

i have tried too many different samples from the web, some how it works but i can't make it works with Firefox 

MozRpel and ff.au3 installed 

right now i can open Firefox with this code, but i still can't control the window of Firefox

; open firefox 

#include <ff.au3>
_FFStart()

; open firefox with random size

 

Share this post


Link to post
Share on other sites
On 12/25/2016 at 5:24 AM, Danp2 said:

Can you show us the code you tried that didn't work? Also, have you considered using WinMove to set the window's size once FF has loaded?

here some of the scripts i tired from the web

Example()

Func Example()
    ; Run Notepad
    Run("notepad.exe")

    ; Wait 10 seconds for the Notepad window to appear.
    Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)

    ; Retrieve the position as well as the height and width of the Notepad window. We will use this when we have to move the window back to the original position.
    Local $aPos = WinGetPos($hWnd)

    ; Move the Notepad to the x, y position of 0, 0 and set the height and width at 200, 200.
    WinMove($hWnd, "", 0, 0, 200, 200)

    ; Wait for 2 seconds to display the new position of the Notepad window.
    Sleep(2000)

    ; Move the Notepad window back to the original position by using the array returned by WinGetPos.
    WinMove($hWnd, "", $aPos[0], $aPos[1], $aPos[2], $aPos[3])

    ; Wait for 2 seconds to display the original position of the Notepad window.
    Sleep(2000)

    ; Close the Notepad window using the handle returned by WinWait.
    WinClose($hWnd)
EndFunc   ;==>Example
; open firefox

#include <ff.au3>
_FFStart()

WinMove(_FFStart(), "", 0, 0, 400, 400)
; For window size 1024 * 768
$customWidth = 1024
$customY = 768
 
If $CmdLine[0] = 1 Then
    WinMove($CmdLine[1], "", 0, 0, $customWidth, $customY)
    _Middle($CmdLine[1], "")
EndIf
 
Func _Middle($win, $txt)
    $size = WinGetClientSize($win, $txt)
    Local $y = (@DesktopHeight / 2) - ($size[1] / 2)
    Local $x = (@DesktopWidth / 2) - ($size[0] / 2)
    Return WinMove($win, $txt, $x, $y)
EndFunc

and here i found some topics about resizing,

i'm not really good in coding the reason i still can't run it with firefox

 

thanks :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Im curious about what you mean with random size, do you really mean random? as in: anything between 0 and total width, and 0 and total height?

This works for me, as i think you described it

$Proc = Run("C:\Program Files (x86)\Mozilla Firefox\firefox.exe")
_Random()
Func _Random()
    WinWait('[CLASS:MozillaWindowClass]')
    Local $aPos = WinGetPos('[CLASS:MozillaWindowClass]')
    Local $Handle = WinGetHandle('[CLASS:MozillaWindowClass]')
    Local $x = Random(0, @DesktopWidth)
    Local $y = Random(0, @DesktopHeight)
    ConsoleWrite('$x - '& $x &' $y - '&$y&@CRLF)
    Sleep(3000)
    WinMove($Handle, '', $aPos[0], $aPos[1], $x, $y)
EndFunc

 

Edited by careca
1 person likes this

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
On 12/25/2016 at 5:24 AM, Danp2 said:

You need to get the handle of the FF window. To do that, you can use _FFWindowGetHandle() --

#include <ff.au3>
_FFStart()

$ffhwnd = _FFWindowGetHandle()

WinMove($ffhwnd, "", 0, 0, 400, 400)

excellent  it works! it was just missing this part for testing the window control

$ffhwnd = _FFWindowGetHandle()

now i will try  Careca's code for the Random part :) 

thanks

Share this post


Link to post
Share on other sites
58 minutes ago, careca said:

Im curious about what you mean with random size, do you really mean random? as in: anything between 0 and total width, and 0 and total height?

This works for me, as i think you described it

$Proc = Run("C:\Program Files (x86)\Mozilla Firefox\firefox.exe")
_Random()
Func _Random()
    WinWait('[CLASS:MozillaWindowClass]')
    Local $aPos = WinGetPos('[CLASS:MozillaWindowClass]')
    Local $Handle = WinGetHandle('[CLASS:MozillaWindowClass]')
    Local $x = Random(0, @DesktopWidth)
    Local $y = Random(0, @DesktopHeight)
    ConsoleWrite('$x - '& $x &' $y - '&$y&@CRLF)
    Sleep(3000)
    WinMove($Handle, '', $aPos[0], $aPos[1], $x, $y)
EndFunc

 

excellent it works like a charm :thumbsup:

exactly what i was looking for, it took me a week trying to figure it out 

now i will just try to keep the resolution of the window at specific size  as in:  anything between 550 and 1280 width x 400 and 720 height
hope it will works

 thank you :)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

2 hours ago, careca said:

 

 

 

 

here is the code for specific size as in:  anything between 1000 and 1330 width x 650 and 720 height
 

$Proc = Run("C:\Program Files (x86)\Mozilla Firefox\firefox.exe")
_Random()
Func _Random()
    WinWait('[CLASS:MozillaWindowClass]')
    Local $aPos = WinGetPos('[CLASS:MozillaWindowClass]')
    Local $Handle = WinGetHandle('[CLASS:MozillaWindowClass]')
    Local $x = Random(1000, 1360, @DesktopWidth)
    Local $y = Random(650, 720, @DesktopHeight)
    ConsoleWrite('$x - '& $x &' $y - '&$y&@CRLF)
    Sleep(3000)
    WinMove($Handle, '', $aPos[0], $aPos[1], $x, $y)
EndFunc

 

Edited by mazz3d
1 person likes this

Share this post


Link to post
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

  • Similar Content

    • vyperhand
      By vyperhand
      I'm struggling to launch a VBS file via autoit using RunWait.  Due to the nature of the deployment tool I am using for said script, I only know that the .vbs files will be in the same directory as my AutoIt-generated .exe, but not what that path will be.  The path will look something like this:
      c:\programdata\vendor\lots\of\folders\randomnumber
      This is generated during deployment and I have no way of predicting the path - therefore, I am not sure how to call back to "same directory" in order to successfully launch the .vbs.
      This line is as close as I have gotten - this fires off the cmd window, but it closes immediately with out information, and the .vbs is not launched.
      RunWait (@ComSpec & " /c" & 'cscript.exe WORKPLEASE.vbs ALL /Q /NoCancel') I thought /c might be the problem, but leaving out the /c element causes me not to even see the momentary CMD window flash by.  Any help will be greatly appreciated, and thanks in advance.
    • Valnurat
      By Valnurat
      I have a ComboBox and I want, when I start writting in it, that it will show me what is the first in the list.
      Like, is I start writting:
      "pe" it  should show me "peter" if that is the first in the list.
      How can I do that?
       
      While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClos ExitLoop Case $idComboBox $sComboRead = GUICtrlRead($idComboBox) Local $iIdx = _ArraySearch($aResult,$sComboRead,0,0,0,0,1,1) Local $aComputerOwner = _AD_GetObjectsInOU("OU=al,DC=AD,DC=AL,DC=ORG","(&(objectclass=computer)(managedby=" & $aResult[$iIdx][0] & "))",Default,"cn") _ArrayDelete($aComputerOwner,0) _GUICtrlListView_SetItemCount($idMylist,UBound($aComputerOwner)) If IsArray($aComputerOwner) Then For $i = 0 To UBound($aComputerOwner) - 1 GUICtrlCreateListViewItem($aComputerOwner[$i], $idMylist) Next Else GUICtrlSetData($idMylist, "No computer|") EndIf EndSwitch WEnd  
    • Faraz
      By Faraz
      I have to open a URL on Mozilla Firefox , cursor is by default userid textbox, had to send userid, send tab, send pwd with flag 1 , send tab, send Enter.
      But Script is Failing to take Password.
      Any Help
       
      #include <Constants.au3>
      #include <IE.au3>
      #include <PassMask.au3>
      If $CmdLine[0] <> 3 Then
          MsgBox($MB_OK, "Usage", "ps_weblogin_FireFox <Url> <Browser Title> <Text to Send>")
      Else
         web_login($CmdLine[1], $CmdLine[2], $CmdLine[3])
      EndIf
      Func web_login($bt_url, $bt_Title, $bt_SendText)
          Local $ff = Run("C:\Program Files (x86)\Mozilla Firefox\firefox.exe " & $bt_url)
              WinWaitActive($bt_Title)
          Sleep(2000)
          ControlSend("","","",$bt_SendText)
      EndFunc
      _______________________________________________
      _______________________________________________
      Func Mask_Password($Password)
          $MaskPassword = $Password
          $MaskPassword = StringReplace($MaskPassword, "#", "||||||#@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "!", "||||||!@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "+", "||||||+@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "^", "||||||^@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "{", "||||||{@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "}", "||||||}@@@@@@")
          $MaskPassword = StringReplace($MaskPassword, "||||||", "{")
          $MaskPassword = StringReplace($MaskPassword, "@@@@@@", "}")
          Return $MaskPassword
      EndFunc
    • Valnurat
      By Valnurat
      Hi.
      I'm trying to add an array to my gui listview, but it fails with
      "C:\Program Files (x86)\AutoIt3\Include\GuiListView.au3" (473) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: DllStructSetData($tBuffer, "Text", $aItems[$iI][0]) DllStructSetData($tBuffer, "Text", ^ ERROR My code is:
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <WindowsConstants.au3> #include <ComboConstants.au3> #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #Include <AD.au3> #include <Array.au3> Opt('MustDeclareVars', 1) Global $aResult[0][2] Local $aNames[4] = ["DKSO","DKKO","SELU","SEES"] Local Const $iWidth = 300, $iHeight = 250, $iW = 85, $iH = 25 Local $hGUI = GUICreate("Find Computer Owner", $iWidth, $iHeight) ; Create a combobox control. Local $idComboBox = GUICtrlCreateCombo("", 2, 2, 296, 20, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT)) ;$WS_VSCROLL Local $idMylist = GUICtrlCreateListView("", 2, 114, 296, 100) Local $idClos = GUICtrlCreateButton("Close", ($iWidth - $iW) / 2, ($iHeight - $iH) - 7 , $iW, $iH) _AD_Open() Local $sFill = "" For $i = 0 to UBound($aNames) -1 Local $aUserInfo = _AD_GetObjectsInOU("OU=Al,DC=ad,DC=al,DC=org","(&(objectCategory=Person)(objectclass=user)(sAMAccountName=" & $aNames[$i] & "*))","","distinguishedName,cn") if @error Then MsgBox(0,@error,@extended) Exit EndIf For $x = $aUserInfo[0][0] To 1 Step -1 If $aUserInfo[$x][0] = "" Or StringInStr($aUserInfo[$x][0], "Resources") > 0 Or StringInStr($aUserInfo[$x][0], "Leavers") > 0 Or StringInStr($aUserInfo[$x][0], "Administration") > 0 Then _ArrayDelete($aUserInfo, $x) EndIf Next _ArrayConcatenate($aResult, $aUserInfo, 1) Next for $i = 0 To UBound($aResult) -1 If $aResult[$i][0] <> "" Then $sFill &= $aResult[$i][1] & "|" EndIf Next _ArrayDisplay($aResult, 'AD ' & UBound($aResult)) $sFill = StringTrimRight($sFill, 1) _GUICtrlComboBox_BeginUpdate($idComboBox) GUICtrlSetData($idComboBox, $sFill, "") _GUICtrlComboBox_EndUpdate($idComboBox) GUISetState(@SW_SHOW, $hGUI) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") _GUICtrlListView_AddColumn($idMylist, "Computername", 296) Local $sComboRead = "" ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClos ExitLoop Case $idComboBox $sComboRead = GUICtrlRead($idComboBox) Local $iIdx = _ArraySearch($aResult,$sComboRead,0,0,0,0,1,1) Local $aComputerOwner = _AD_GetObjectsInOU("OU=al,DC=AD,DC=AL,DC=ORG","(&(objectclass=computer)(managedby=" & $aResult[$iIdx][0] & "))",Default,"cn") _ArrayDelete($aComputerOwner,0) _ArrayDisplay($aComputerOwner) _GUICtrlListView_SetItemCount($idMylist,UBound($aComputerOwner)) If IsArray($aComputerOwner) Then MsgBox(0,"Test",$sComboRead) _GUICtrlListView_AddArray($idMylist, $aComputerOwner) ; <---- it fails Else GUICtrlSetData($idMylist, "No computer|") EndIf EndSwitch WEnd _AD_Close() ; Delete the previous GUI and all controls. GUIDelete($hGUI) Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo ; Local $tBuffer $hWndListView = $idMylist If Not IsHWnd($idMylist) Then $hWndListView = GUICtrlGetHandle($idMylist) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) _DebugPrint("$NM_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode & @CRLF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) ; No return value EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @CRLF & _ "+======================================================" & @CRLF & _ "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _ "+======================================================" & @CRLF) EndFunc ;==>_DebugPrint Do I do it wrong?
       
      Thank you in advanced.
    • Errious
      By Errious
      Hello,
      i am searching for a function that allows me some very specific functions for Screen Captures.
       
      First should be the possibillity to create a Screenshot from a specific window and this is possibly under another window but has to stay there and not getting forced to be in the first - layer position if this is clear enough :-) The other thing should be the ability to create a Screen Capture every couple minutes or a specific period.  
      I tried a lot of Screen Capture tools but neither can do both together.
      Also my try to create my own script with AutoIT failed, because of missing knoweledge about how to use it for this specific reasons, would be very kind if someone can tell me in the first place if this is possible at all and maybe someone has allready an idea about how to realize it?
       
      best regards