Jump to content

BitByteBit

Active Members
  • Posts

    129
  • Joined

  • Last visited

1 Follower

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

BitByteBit's Achievements

Adventurer

Adventurer (3/7)

1

Reputation

  1. In the first example below Ubound($Array) - 1 is evaluated every cycle for no reason. Is there any significant benefit to doing the calculation before such as in the 2nd example? Global $Array[100] For $i = 0 to Ubound($Array) - 1 ;Do something Next Global $Array[100], $a = Ubound($Array) - 1 For $i = 0 to $a ;Do something Next
  2. This should do the trick. You will however loose the order of your links, is that a problem? #include<array.au3> #include<file.au3> Dim $aFile _FileReadToArray(@DesktopDir & '\Codes2.txt', $aFile) _ArrayDelete($aFile, 0) _ArraySort($aFile) For $i = UBound($aFile) - 1 To 1 Step -1 If $aFile[$i] = $aFile[$i - 1] Then _ArrayDelete($aFile, $i) Next _ArrayDisplay($aFile)
  3. My point was that you should try using ControlFocus.
  4. !+{F4} is Alt + Shift + F4, not Alt + F4. Does ControlFocus help? The same behavior you described is exhibited in the following example without it. Run('notepad') Run('explorer /root,') WinWaitActive('Untitled') WinWaitActive('Computer') ControlFocus('Untitled', '', 'Edit1') ControlSend('Untitled', '', 'Edit1', '!{F4}') Exit
  5. Use FileRead to read the text, then use ControlSetText or ClipPut and Send("^v").
  6. Thanks for your reply, perhaps a little more background information would be appropriate. One day, I thought about the amount of time I spend on Facebook, I then thought about the amount of time my 10 year old nephew spends on it. As a joke I thought about making an application that limits the amount of time spent on Facebook. A week later, late at night in a fit of boredom I started making this program, I viewed it as a challenge and wanted to see how fast I could do it. Unfortunately I've got stuck at a hurdle, whilst the program works in most situations; knowing it's flawed really bugs me. Whilst your method would work to see how long the user is connected to Facebook, that is not my goal. My goal is to time how long Facebook is active or visible, if the user minimizes the window the the timer stops.
  7. I'm writing an application to monitor the amount of time spent on Facebook. When you are viewing someones profile the string "Facebook" is not found in the window title, because of this I decided to use PixelSearch in addition to checking the active window's title. The following function checks if Facebook is open, it works okay; however if the pixel I'm searching for on the screen is present in another window then it will stop searching and return false. In theory it should continue searching the rest of the screen from the last location, aaannd this is where I'm stuck. Func _OnFacebook() If WinActive('Facebook') Then Return True Local $iX = 0, $iY = 0 While 1 $aLoc1 = PixelSearch($iX, $iY, @DesktopWidth, @DesktopHeight, 0x133783) If Not @error Then If PixelGetColor($aLoc1[0] + 20, $aLoc1[1]) = 0x133783 Then Return True Else ConsoleWrite('Found pixel, but not Facebook!' & @CRLF) $iX = $aLoc1[0] + 1 $iY = $aLoc1[1] EndIf Else Return False EndIf WEnd EndFunc ;==>_OnFacebook Here is the full code. Opt('GuiOnEventMode', 1) Opt('TrayAutoPause', 0) Opt('TrayOnEventMode', 1) Opt('TrayMenuMode', 1) Global $iTotal = 0, $iLimit = 3600000, $aLoc1, $bHidden = False Global $iHours, $iMins, $iSecs $hGUI = GUICreate('Anti Facebook', 70, 90, -1, -1, 0x00400000) GUISetOnEvent(-3, '_Exit') GUISetBkColor(0x1F1F1F) $hLabel = GUICtrlCreateLabel('Total time:', 25, 10) GUICtrlSetColor(-1, 0xFFFFFF) $hLabel2 = GUICtrlCreateLabel('0:00', 80, 10) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateButton('Reset', 24, 32, 78) GUICtrlSetOnEvent(-1, '_Reset') GUISetState() $iCurrent = @MDAY TraySetClick(8) TraySetOnEvent(-7, '_ToggleGUI') TrayCreateItem('Exit') TrayItemSetOnEvent(-1, '_Exit') While 1 If $iCurrent <> @MDAY Then $iTotal = 0 If _OnFacebook() Then If $iTotal >= $iLimit Then _CloseFacebook() $T1 = TimerInit() While _OnFacebook() $iTicks = Mod(Int((TimerDiff($T1) + $iTotal) / 1000), 3600) $iSecs = Mod($iTicks, 60) If $iSecs < 10 Then $iSecs = '0' & $iSecs GUICtrlSetData($hLabel2, Int($iTicks / 60) & ':' & $iSecs) If $iTotal + TimerDiff($T1) >= $iLimit Then _CloseFacebook() Sleep(990) WEnd $iTotal += TimerDiff($T1) EndIf Sleep(1000) WEnd Func _Exit() Exit EndFunc ;==>_Exit Func _OnFacebook() If WinActive('Facebook') Then Return True Local $iX = 0, $iY = 0 While 1 $aLoc1 = PixelSearch($iX, $iY, @DesktopWidth, @DesktopHeight, 0x133783) If Not @error Then If PixelGetColor($aLoc1[0] + 20, $aLoc1[1]) = 0x133783 Then Return True Else $iX = $aLoc1[0] + 1 $iY = $aLoc1[1] EndIf Else Return False EndIf WEnd EndFunc ;==>_OnFacebook Func _CloseFacebook() If WinActive('Facebook') Then Send('^w') ElseIf IsArray($aLoc1) Then $aOld = MouseGetPos() MouseClick('Primary', $aLoc1[0], $aLoc1[1], 1, 0) MouseMove($aOld[0], $aOld[1], 0) Send('^w') EndIf MsgBox(48, 'Limit Exceeded!', 'You have been on Facebook too long!' & @CRLF & 'Go outside and play!') EndFunc ;==>_CloseFacebook Func _ToggleGUI() $bHidden = $bHidden = False If $bHidden Then WinSetState($hGUI, '', @SW_HIDE) Else WinSetState($hGUI, '', @SW_SHOW) WinActivate($hGUI) EndIf EndFunc ;==>_ToggleGUI Func _Reset() GUICtrlSetData($hLabel2, '0:00') $iTotal = 0 $T1 = TimerInit() EndFunc ;==>_Reset Thank you for your time.
  8. You want to use CtrlSetOnEvent with your List View Items rather then the List View control itself. I personally use an array to hold all my control handles. Hope the code below helps. Opt('GuiOnEventMode', 1) Global $hGui, $hList, $hListItems[3] $hGui = GUICreate("Listview.", 515, 262, 192, 125) $hList = GUICtrlCreateListView("1", 0, 0, 420, 210) For $i = 0 To 2 $hListItems[$i] = GUICtrlCreateListViewItem("Item " & $i, $hList) GUICtrlSetOnEvent($hListItems[$i], '_ListViewEvent') Next GUISetOnEvent(-3, '_Exit') GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func _ListViewEvent() For $i = 0 To $hListItems[0] If @GUI_CtrlId = $hListItems[$i] Then ExitLoop Next ConsoleWrite('List view item clicked - ' & GUICtrlRead($hListItems[$i]) & @CRLF) EndFunc ;==>_ListViewEvent Func _Exit() Exit EndFunc ;==>_Exit
  9. When using a macro within a loop, is it "better" to assign a variable's value to the macros's value? In essence my question is, is a macro a variable or a function. Found my answer in the help file. "Macros that are special read-only variables" . Can someone delete this thread? Global $aArray[4][2] For $i = 0 to 3 If $aArray[$i][0] = @GUI_CtrlId Then Return $aArray[$i][1] Next Or Global $aArray[4][2] $hCtrl = @GUI_CtrlId For $i = 0 to 3 If $aArray[$i][0] = $hCtrl Then Return $aArray[$i][1] Next ;An exercise in futility?
  10. Untested. AdlibRegister('_FakeActivity', 900000) ;Run every 15 mins. Func _FakeActivity() ControlClick($hGUI, '', 'Internet Explorer_Server1', 'Primary', 1, 1, 1) EndFunc
  11. Or use: WinSetOnTop I'm looking into the problem of inactivity. As I see it there are two solutions. Check to see if the continue listening button exists, click when it does. Fake some sort of user activity within the IE window every 15 mins.
  12. This is what I've got so far. _SetVolume doesn't work. #AutoIt3Wrapper_Icon=grooveshark.ico #AutoIt3Wrapper_UseX64=n #include<ie.au3> Opt('GuiOnEventMode', 1) Opt('GUIResizeMode', 102) Opt("TrayAutoPause", 0) Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) ;Create tray items. $Dummy = TrayCreateItem('Nothing playing') TrayItemSetState($Dummy, 128) TrayCreateItem('') $sStr = StringSplit('Play|Next|Previous||Shuffle|Repeat||Exit', '|') For $i = 1 To $sStr[0] TrayCreateItem($sStr[$i]) If $sStr[$i] Then TrayItemSetOnEvent(-1, '_' & $sStr[$i]) Next TraySetClick(8) TraySetOnEvent(-8, '_GuiMini') ;Set hotkeys. HotKeySet('!d', '_Debug') ;HotKeySet('{ESC}', '_Exit2') HotKeySet('{MEDIA_PLAY_PAUSE}', '_Play') HotKeySet('{MEDIA_NEXT}', '_Next') HotKeySet('{MEDIA_PREV}', '_Prev') ;Variables. Global $oIE, $hGUI, $bActive = False, $oArtist = 'Artist', $oSong = 'Song', $sCurrent Global Const $iWidth = 800, $iHeight = 500, $iPid = @AutoItPID ;Create Gui. $oIE = _IECreateEmbedded() $hGUI = GUICreate('Grooveshark', $iWidth, $iHeight, -1, -1, BitOR(0x00010000, 0x00020000)) $oCtrl = GUICtrlCreateObj($oIE, -2, -2, $iWidth + 178, $iHeight - 24) GUISetOnEvent(-3, '_Exit') GUISetOnEvent(-4, '_GuiMini') GUISetState() _IENavigate($oIE, 'http://grooveshark.com') ;Media control. Func _Next() ;~ TrayItemSetState(@TRAY_ID, 4) $oNext = _IEGetObjByName($oIE, 'player_next') _IEAction($oNext, 'click') EndFunc ;==>_Next Func _Play() ;~ TrayItemSetState(@TRAY_ID, 4) $oPlay = _IEGetObjByName($oIE, 'player_play_pause') _IEAction($oPlay, 'click') EndFunc ;==>_Play Func _Prev() ;~ TrayItemSetState(@TRAY_ID, 4) $oPrev = _IEGetObjByName($oIE, 'player_previous') _IEAction($oPrev, 'click') EndFunc ;==>_Prev Func _Shuffle() $oShuffle = _IEGetObjByName($oIE, 'player_shuffle') _IEAction($oShuffle, 'click') EndFunc ;==>_Shuffle Func _Repeat() ;~ TrayItemSetState(@TRAY_ID, 4) $oRepeat = _IEGetObjByName($oIE, 'player_loop') _IEAction($oRepeat, 'click') EndFunc ;==>_Repeat Func _GetVolume() ;~ <A style="BOTTOM: 0%" class="ui-slider-handle ui-state-default ui-corner-all" href="#" jQuery15107891455831978822="11"></A> $hfind = _IETagNameGetCollection($oIE, "A") For $h In $hfind If String($h.className) = "ui-slider-handle ui-state-default ui-corner-all" Then $iVol = StringRegExp(_IEPropertyGet($h, 'outerhtml'), '["]BOTTOM:.(.*?)%["]', 1) If IsArray($iVol) Then $iVol = $iVol[0] ConsoleWrite($iVol & @CRLF) Return $iVol Else Return -1 EndIf ExitLoop EndIf Next Return -1 EndFunc ;==>_GetVolume Func _SetVolume($iVol) $oTags = _IETagNameGetCollection($oIE, "div") For $oTag In $oTags If String($oTag.id) = "volumeSlider" Then $iVol = StringRegExpReplace(StringRegExpReplace(_IEPropertyGet($oTag, 'outerhtml'), '["]BOTTOM:.(.*?)%["]', '"BOTTOM: ' & $iVol & '%";', 1), '["]HEIGHT:.(.*?)%["]', '"HEIGHT: ' & $iVol & '%";', 1) _IEPropertySet($oTag, 'outerhtml', $iVol) ConsoleWrite($iVol & @CRLF) ExitLoop EndIf Next Return -1 EndFunc ;==>_SetVolume ;GUI. Func _GuiMini() $bActive = ($bActive = False) If $bActive Then GUISetState(@SW_HIDE, $hGUI) Else GUISetState(@SW_SHOW, $hGUI) EndIf EndFunc ;==>_GuiMini ;Misc. Func _Debug() ;~ _SetVolume(50) EndFunc ;==>_Debug Func _Exit() Exit EndFunc ;==>_Exit Func _Exit2() If WinActive($hGUI) Then Exit EndFunc ;==>_Exit2 Func _RM() Local $ai = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $iPid) $ai = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai[0]) DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai[0]) EndFunc ;==>_RM ;Reduce memory usage every 5 seconds. AdlibRegister('_RM', 5000) ;Main Loop. $oTags = _IETagNameGetCollection($oIE, "A") While 1 For $oTag In $oTags If StringInStr($oTag.className, 'currentSongLink') Then $oSong = String($oTag.title) ElseIf StringInStr($oTag.className, 'artist') Then $oArtist = String($oTag.title) ExitLoop EndIf Next If $oSong & ' ~ ' & $oArtist <> $sCurrent Then $sCurrent = $oSong & ' ~ ' & $oArtist WinSetTitle($hGUI, '', 'GrooveShark ~ ' & $sCurrent) TrayItemSetText($Dummy, $sCurrent) ;Toast? EndIf Sleep(1000) WEnd
  13. Hope this helps. #include<array.au3> ;Only needed to use _ArrayDisplay! Global $Array[4] $Array[0] = 'This' $Array[1] = 'is' $Array[2] = 'an' $Array[3] = 'array.' _ArrayDisplay($Array) ;Print elements 0 through to 3. For $i = 0 To 3 ConsoleWrite($Array[$i] & @CRLF) Nexthttp://www.autoitscript.com/wiki/Arrays
  14. You're need to use the IE object. The code below will error unless you wait for the page to load. _IEImgClick($oIE, "http://www.autoitscript.com/forum/public/style_images/autoit/logo.png","src")
×
×
  • Create New...