Sign in to follow this  
Followers 0
IanN1990

[Solved] Code Overlook

23 posts in this topic

#1 ·  Posted (edited)

Sense i joined Autoit i have been writing a personal autoit script for making my computer more personal. After 4months now of writing its starting to use almost 1 CPU all the time. I was wondering if someone could look though it and point out any problems with my coding style in terms of peformance or ideas for making it better.

One idea i had, i remember seeing a script on these forums that changings the transpary depending on the window hover, so if i was to make lots of invisible GUIs showing the programs on hover.

PS i tryed to upload a picture 5760x1080 (which is my desktop with GUI plans) .jpg but it was 1.14 MB more then the limit

#Region Includes
#Include <misc.au3>
#include <constants.au3>
#include <winapi.au3>
#include <windowsconstants.au3>
#include<ie.au3>

HotKeySet('{SCROLLLOCK}', '_ScrollLock')
Hotkeyset('{Volume_UP}', '_VolumeUp')
Hotkeyset('{Volume_Down}', '_VolumeDown')
HotKeySet('{MEDIA_PlAY_PAUSE}', '_Play')
HotKeySet('{MEDIA_NEXT}', '_Next')
HotKeySet('{MEDIA_PREV}', '_Prev')
HotKeySet('{MEDIA_STOP}', '_StopDelayed')

Opt('WinTitleMatchMode', 2 )
local $Time= ' /starttray'
Local $Var=' user32.dll,LockWorkStation'
local $PC_Lock=0
local $AltRan=0
local $Sound=0
local $ChatHover=1
local $TaskbarHovered=0
local $Run=0
local $UIRun=0
local $Loop=0
local $UILoop=0
local $ActiveDeskLoop=0
local $DeskLoop=0
local $MediaPlayer = 0
local $Flash
local $FF
local $IE
Local $KMPMain
local $Dimmed
local $leftscreen
local $rightscreen

OnAutoItExitRegister('TurnOff')
DllCall('kernel32.dll', 'int', 'SetProcessShutdownParameters', 'long', 0x3FF, 'long', 0)

$TaskBarGUI = GUICreate('TaskBar', 0, 0)
Winflash($TaskbarGUI, '', 2, 25)
Taskbar(0)
#EndRegion Includes

While 1
sleep(500)

;Process Check Statements
If ProcessExists('Login.exe') Then
    $PC_Lock=0
ElseIf ProcessExists('Media.exe') Then
    _F12()
ElseIf ProcessExists('IE.exe') Then
    $ie = _IECreate('about:blank')
    WinSetState('Explorer','',@SW_MAXIMIZE)
    SendKeepActive('[Class:IEFrame]')
    Send('www.bbciplayer.co.uk')
    Send('{Enter}')
EndIf

;Main Scipt
If $PC_Lock=0 Then
    
    ;Timer Loops
    If $Run=1 Then
    $Loop = $Loop + 1
        If $Loop = 2 Then
        $Loop=0
        $Run=0
        EndIf
    EndIf

    If $UIRun=1 Then
    $UILoop = $UILoop + 1
        If $UILoop = 2 Then
        $UILoop=0
        $UIRun=0
        $GUITaskBar = WinGetHandle($TaskbarGUI)
        _WinAPI_SetWindowLong($GUITaskBar, $GWL_Exstyle, 0x08000000)
        EndIf
    EndIf

    ;KMPlayer
    If ProcessExists('KMPlayer.exe') or $KMPMain=1 Then
        $KMPControlPos = ControlGetPos('[CLASS:Winamp v1.x]','','[CLASS:TSkinPanel; INSTANCE:6]')
        If IsArray($KMPControlPos) Then
            If $KMPControlPos[2] = @DesktopWidth And $KMPControlPos[3] = @DesktopHeight Then
                If $KMPMain=0 then
                Dimmed(1)
                $KMPMain=1
                EndIf
            Else
                If $KMPMain=1 Then
                $KMPMain=0
                Dimmed(0)
                EndIf
            EndIf
        Else
            If $KMPMain=1 Then
            Dimmed(0)
            $KMPMain=0
            EndIf
        EndIf
    EndIf

    ;FlashPlayer
    If ProcessExists('Firefox.exe') or ('iexplore.exe') Then
        If WinExists('Adobe Flash Player') Then
            If $Flash = 0 Then
            WinMove('Adobe Flash Player', "", 0, 0, 1920, 1080)
            Dimmed(1)
            $Flash = 1
                If ProcessExists('firefox.exe') Then
                WinSetState('Firefox','',@SW_MINIMIZE)
                $FF=1
                EndIf
                If ProcessExists('iexplore.exe') Then
                WinSetState('Explorer','',@SW_MINIMIZE)
                $IE=1
                EndIf
            EndIf
        Else
            If $Flash=1 Then
            $Flash=0
                If $FF = 1 Then
                $FF = 0
                WinSetState('Firefox','',@SW_MAXIMIZE)
                EndIf
                If $IE = 1 Then
                $IE = 0
                WinSetState('Firefox','',@SW_MAXIMIZE)
                EndIf
            sleep(200)
            Dimmed(0)
            EndIf
        EndIf
        If ProcessExists('iexplore.exe') And WinExists('BBC iPlayer -') Then
        $ie.document.body.scroll = 'NO'
        $ie.document.body.style.overflow = 'hidden'
        EndIf
    EndIf

    ;Alt-Tabs
    If ProcessExists('Steam.exe') and ProcessExists('wmplayer.exe') and ProcessExists('Skype.exe') and ProcessExists('wmplayer.exe') then
        If $AltRan = 0    Then
        $AltMsn = WinGetHandle('[CLASS:MSBLWindowClass]')
        $AltSkype = WinGetHandle('[CLASS:tSkMainForm]')
        $AltMedia = WinGetHandle('[CLASS:WMPlayerApp]')
        $AltSteam = WinGetHandle('Friends')
            If BitAND(_WinAPI_GetWindowLong($AltMsn, $GWL_Exstyle), 0x08000000) Then
            Else
            _WinAPI_SetWindowLong($AltMsn, $GWL_Exstyle, 0x08000000)
            EndIf    
            If BitAND(_WinAPI_GetWindowLong($AltSkype, $GWL_Exstyle), 0x08000000) Then
            Else
            _WinAPI_SetWindowLong($AltSkype, $GWL_Exstyle, 0x08000000)
            EndIf    
            If BitAND(_WinAPI_GetWindowLong($AltMedia, $GWL_Exstyle), 0x08000000) Then
            Else
            _WinAPI_SetWindowLong($AltMedia, $GWL_Exstyle, 0x08000000)
            EndIf    
            If BitAND(_WinAPI_GetWindowLong($AltSteam, $GWL_Exstyle), 0x08000000) Then
            Else    
            _WinAPI_SetWindowLong($AltSteam, $GWL_Exstyle, 0x08000000)
            $AltRan = 1
            EndIf    
        EndIf
    Else
    $AltRan = 0
    EndIf

    ;HideDesktop
    If winactive('[Class:Progman]') Then
        If WinExists('Desktop Background') Then
            WinClose('Desktop Background')
            ShellExecute('D:\Pictures\01¦ Wallpapers &amp;amp; Display Pictures\Tri-Screen Wallpapers')
        EndIf
    $DeskLoop = 0
    $ActiveDeskLoop = 0
    ControlShow('Program Manager', '', '[CLASS:SysListView32; INSTANCE:1]')
    $ActiveDeskLoop = $ActiveDeskLoop + 1
        If $ActiveDeskLoop = 30 Then
        $ActiveDeskLoop = 0
        $pos1 = MouseGetPos()
        sleep(750)
        $pos2 = MouseGetPos()
            If $pos1[0] = $pos2[0] Then
                If $pos1[1] = $pos2[1] Then
                WinActivate('Friends')
                ControlHide('Program Manager', '', '[CLASS:SysListView32; INSTANCE:1]')
                EndIf
            EndIf
        EndIf
    ElseIf WinExists('', "FolderView") then
            $DeskLoop = $DeskLoop + 1
            If $DeskLoop = 20 Then
            ControlHide('Program Manager', '', '[CLASS:SysListView32; INSTANCE:1]')
            EndIf
    EndIf

    ;Show Chat Messages
    $Steam = WinGetState('- Chat', '')
    $MsN = WinGetState('[Class:TConversationForm]', '')
    $Skype = WinGetState('[Class:IMWindowClass]', '')
    If BitAnd($Steam, 16) Then
        If  _Flash('- Chat') &amp;lt;&amp;gt; 0 Then
        WinSetState('- Chat','',@SW_RESTORE)
        WinSetOnTop('- Chat', '', 1)
        EndIf
    ElseIf BitAnd($MsN, 16) Then
        WinSetState('[Class:TConversationForm]','',@SW_RESTORE)
        WinSetOnTop('[Class:TConversationForm]', '', 1)
    ElseIf BitAnd($Skype, 16) Then
        WinSetState('[Class:IMWindowClass]','',@SW_RESTORE)
        WinSetOnTop('[Class:IMWindowClass]', '', 1)
    EndIf

    If WinExists('- Steam', '') Then
        If WinActive('[Class:MozillaWindowClass]') Then
        Else
        WinSetState('- Steam','',@SW_MINIMIZE)
        EndIf
    EndIf

    ;Chat Hover
    $pos = MouseGetPos()
    If $pos[0] &amp;lt;= -1918 Then
        If $pos[1] &amp;lt;=360 and $ChatHover=0  then
        $ChatHover=1
        $MsN1 = WinGetState('[Class:MSBLWindowClass]', '')
            If BitAnd($MsN1, 16) Then
            WinSetState('[Class:MSBLWindowClass]','',@SW_RESTORE)
            Winmove('[Class:MSBLWindowClass]', '', -1920, 0, 220, 510,1)
            WinSetOnTop('[Class:MSBLWindowClass]', '', 1)
            Else
            winmove('[Class:MSBLWindowClass]', '', -1920, 0, 220, 510,1)
            WinSetOnTop('[Class:MSBLWindowClass]', '', 1)
            EndIf
        ElseIf $pos[1] &amp;gt;=360 and $pos[1] &amp;lt;=720 and  $ChatHover=0 Then
         $ChatHover=1
        $Steam1 = WinGetState('Friends', '')
            If BitAnd($Steam1, 16) Then
            WinSetState('Friends','',@SW_RESTORE)
            winmove('Friends', '', -1920, 0, 220, 1080,1)
            WinSetOnTop('Friends', '', 1)
            Else
            winmove('Friends', '', -1920, 0, 220, 1080,1)
            WinSetOnTop('Friends', '', 1)
            EndIf
        ElseIf $pos[1] &amp;gt;=720 and $pos[1] &amp;lt;=1080 and $ChatHover=0 Then
        $ChatHover=1
        $Skype1 = WinGetState('[Class:tSkMainForm]', '')
            If BitAnd($Skype1, 16) Then
            WinSetState('[Class:tSkMainForm]','',@SW_RESTORE)
            winmove('[Class:tSkMainForm]', '', -1920, 511, 220, 570,1)
            WinSetOnTop('[Class:tSkMainForm]', '', 1)
            Else
            winmove('[Class:tSkMainForm]', '', -1920, 511, 220, 570,1)
            WinSetOnTop('[Class:tSkMainForm]', '', 1)
            EndIf
        EndIf
    ElseIf $pos[0] &amp;gt;= 3839 Then
        If $pos[1] &amp;lt;=360 and $ChatHover=0  then
        $ChatHover=1
        $MsN1 = WinGetState('[Class:MSBLWindowClass]', '')
            If BitAnd($MsN1, 16) Then
            WinSetState('[Class:MSBLWindowClass]','',@SW_RESTORE)
            winmove('[Class:MSBLWindowClass]', '', 3620, 0, 220, 510,1)
            WinSetOnTop('[Class:MSBLWindowClass]', '', 1)
            Else
            winmove('[Class:MSBLWindowClass]', '', 3620, 0, 220, 510,1)
            WinSetOnTop('[Class:MSBLWindowClass]', '', 1)
            EndIf
        ElseIf $pos[1] &amp;gt;=360 and $pos[1] &amp;lt;=720 and  $ChatHover=0 Then
         $ChatHover=1
        $Steam1 = WinGetState('Friends', '')
            If BitAnd($Steam1, 16) Then
            WinSetState('Friends','',@SW_RESTORE)
            winmove('Friends', '', 3620, 0, 220, 1080,1)
            WinSetOnTop('Friends', '', 1)
            Else
            winmove('Friends', '', 3620, 0, 220, 1080,1)
            WinSetOnTop('Friends', '', 1)
            EndIf
        ElseIf $pos[1] &amp;gt;=720 and $pos[1] &amp;lt;=1080 and $ChatHover=0 Then
        $ChatHover=1
        $Skype1 = WinGetState('[Class:tSkMainForm]', '')
            If BitAnd($Skype1, 16) Then
            WinSetState('[Class:tSkMainForm]','',@SW_RESTORE)
            winmove('[Class:tSkMainForm]', '', 3620, 510, 220, 570,1)
            WinSetOnTop('[Class:tSkMainForm]', '', 1)
            Else
            winmove('[Class:tSkMainForm]', '', 3620, 510, 220, 570,1)
            WinSetOnTop('[Class:tSkMainForm]', '', 1)
            EndIf
        EndIf                
    Else
        If $pos[0] &amp;lt;= -1710 or $pos[0] &amp;gt;= 3630 and $ChatHover=1 Then
        ElseIf $Chathover=1 then
        $Chathover=0
        winmove('Friends', '', -2500, 0, 220, 1080,1)
        winmove('[Class:MSBLWindowClass]', '', -2500, 0, 220, 510,1)
        winmove('[Class:tSkMainForm]', '', -2500, 0,220, 530,1)
        EndIf
    EndIf

    ;Taskabr
    $size = WinGetPos('[Class:Shell_TrayWnd]')
    $pos = MouseGetPos()
    If $pos[0] &amp;lt; 0 Then
        If $pos[0] &amp;gt; -30 Then
        sleep(500)
        $pos = MouseGetPos()
            If $pos[0] &amp;lt; 0 and $pos[0] &amp;gt; -30 and $TaskbarHovered=0 Then
                If $size[0] &amp;lt; 0 then
                $TaskbarHovered=1
                WinSetOnTop('[Class:Shell_TrayWnd]', '', 1)
                WinActivate('[Class:Shell_TrayWnd]')
                Taskbar(1)
                Else
                $TaskbarHovered=1
                WinSetTrans('[Class:Shell_TrayWnd]', '', 1)
                WinActivate('[Class:Shell_TrayWnd]')
                $pos1 = MouseGetPos()
                BlockInput(1)
                MouseClickDrag('left', 1925, 875,-5, 875, 0)
                BlockInput(0)
                MouseMove($Pos1[0], $Pos1[1], 0)
                Taskbar(1)
                EndIf
            EndIf
        ElseIf    $pos[1] &amp;lt; 3 then    
        sleep(250)
        $pos = MouseGetPos()
            If $pos[1] &amp;lt; 3 Then
                If $Run = 0 Then
                    If ProcessExists('iexplore.exe') Then
                    $Internet = WinGetState('[Class:IEFrame]', '')
                        If BitAnd($Internet, 16) Then
                        WinSetState('[Class:IEFrame]','',@SW_MAXIMIZE)
                        Else
                        WinSetState('[Class:IEFrame]','',@SW_MINIMIZE)
                        EndIf
                    Else
                    $ie = _IECreate('about:blank')
                    WinSetState('Explorer','',@SW_MAXIMIZE)
                    SendKeepActive('[Class:IEFrame]')
                    Send('www.bbciplayer.co.uk')
                    Send('{Enter}')
                    EndIf    
                $Run = 1
                EndIf                    
            EndIf        
        ElseIf    $pos[1] &amp;gt; 1077 then
        sleep(100)
        $pos1 = MouseGetPos()
            If $pos1[1] &amp;gt; 1077 Then
                If $Run = 0 Then
                    If $pos1[0] &amp;lt; -960 Then
                    $KMP= WinGetState('[CLASS:Winamp v1.x]', '')
                        If BitAnd($KMP, 2) Then
                            $a = WinGetPos('[CLASS:Winamp v1.x]','')
                            If IsArray($a) Then
                                If $a[0] = 0 And $a[1] = 0 Then
                                SendKeepActive('[Class:Winamp v1.x]')
                                Send('{Enter}')
                                controlclick("[Class:Winamp v1.x]", "", "[ID:1050156]", "left", 1, 1825, 12)
                                Else
                                controlclick("[Class:Winamp v1.x]", "", "[ID:1050156]", "left", 1, 1825, 12)
                                EndIf
                            EndIf
                        Else
                        controlclick('[Class:Shell_TrayWnd]', 'User Promoted NotIfication Area', '[CLASS:ToolbarWindow32; INSTANCE:1]', 'left', 13, 12)
                        EndIf
                    $Run = 1
                    Else
                    $WMP= WinGetState('[Class:WMPlayerApp]', '')
                        If BitAnd($WMP, 32) Then
                        WinSetState('[Class:WMPlayerApp]','',@SW_MINIMIZE)
                        WinMove('[Class:WMPlayerApp]', '', 960, 1230)                        
                        Else
                        WinSetState('[Class:WMPlayerApp]','',@SW_MAXIMIZE)
                        EndIf
                    $Run = 1
                    EndIf
                EndIf    
            EndIf            
        ElseIf $pos[0] &amp;lt; -255 Then
        $Thumbnail = WinGetState('[Class:TaskListThumbnailWnd]', '')
        $Nofication = WinGetState('[Class:NotIfyIconOverflowWindow]', '')
            If $TaskbarHovered=1 and WinActive('Start menu') or WinActive('[Class:TaskListThumbnailWnd]') or BitAnd($Thumbnail, 2) or BitAnd($Nofication, 2)  Then
            Else
                If $TaskbarHovered = 1 and $size[0] &amp;lt; 0 Then
                $TaskbarHovered = 0
                Taskbar(0)        
                EndIf
            EndIf
        EndIf
    ElseIf $pos[0] &amp;gt; 1920 Then
        If $pos[0] &amp;lt; 1950 Then
            sleep(500)
            $pos = MouseGetPos()
                If $pos[0] &amp;gt; 1920 and $pos[0] &amp;lt; 1950 and $TaskbarHovered=0 Then
                    If $size[0] &amp;gt; 0 then
                    $TaskbarHovered=1
                    WinSetOnTop('[Class:Shell_TrayWnd]', '', 1)
                    WinActivate('[Class:Shell_TrayWnd]')    
                    Taskbar(1)
                    Else
                    $TaskbarHovered=1
                    WinSetTrans('[Class:Shell_TrayWnd]', '', 1)
                    WinSetOnTop('[Class:Shell_TrayWnd]', '', 1)
                    WinActivate('[Class:Shell_TrayWnd]')
                    $pos1 = MouseGetPos()
                    BlockInput(1)
                    MouseClickDrag('left', -5, 875, 1925, 875, 0)
                    BlockInput(0)
                    MouseMove($Pos1[0], $Pos1[1], 0)
                    Taskbar(1)
                    EndIf
                EndIf
        ElseIf    $pos[1] &amp;lt; 3 then    
        sleep(250)
        $pos = MouseGetPos()
            If $pos[1] &amp;lt; 3 Then
                If $Run = 0 Then
                    If ProcessExists('Firefox.exe') Then
                        $Firefox = WinGetState(' - Mozilla Firefox', '')
                            If BitAnd($Firefox, 16) Then
                            WinSetState('Firefox','',@SW_MAXIMIZE)
                            Else
                            WinSetState('Firefox','',@SW_MINIMIZE)
                            EndIf
                    Else
                    Run('C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
                    sleep(750)
                    $FFPos = WinGetPos('[Class:MozillaWindowClass]','')
                        If IsArray($FFPos) Then
                            If $FFPos[0] &amp;lt; 1800 Then
                                WinSetTrans(' - Mozilla Firefox', '', 0)
                                WinSetState(' - Mozilla Firefox', '', @SW_RESTORE)
                                sleep(25)
                                WinMove(' - Mozilla Firefox', '', 1921, 0)
                                sleep(25)
                                winclose(' - Mozilla Firefox')
                                sleep(500)
                                Run('C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
                                sleep(500)
                                WinSetState(' - Mozilla Firefox', '', @SW_MAXIMIZE)    
                            EndIf
                        EndIf                            
                EndIf
            $Run = 1
            EndIf                    
        EndIf        
    ElseIf    $pos[1] &amp;gt; 1077 then
    sleep(100)
    $pos = MouseGetPos()
        If $pos[1] &amp;gt; 1077 Then
            If $run = 0 Then
                If $pos[0] &amp;gt; 2880 Then

                Else

                EndIf    
                $run = 1
            EndIf
        EndIf            
    ElseIf $pos[0] &amp;gt;2175 Then
    $Thumbnail = WinGetState('[Class:TaskListThumbnailWnd]', '')
    $Nofication = WinGetState('[Class:NotIfyIconOverflowWindow]', '')
        If $TaskbarHovered=1 and WinActive('Start menu') or WinActive('[Class:TaskListThumbnailWnd]') or BitAnd($Thumbnail, 2) or BitAnd($Nofication, 2)  Then
        Else
            If $TaskbarHovered = 1 and $size[0] &amp;gt; 0 Then
            $TaskbarHovered = 0
            Taskbar(0)        
            EndIf
        EndIf
    EndIf
Else
    If $TaskbarHovered = 1 Then
        $TaskbarHovered = 0
            Taskbar(0)
        EndIf
EndIf
    
Else

$state9 = WinGetState('[Class:DV2ControlHost]', '')
    If WinExists('[Class:#32768]') or BitAnd($state9, 2) or WinActive('[Class:CabinetWClass]') or WinActive('[Class:Shell_TrayWnd]') or WinActive('[Class:MozillaWindowClass]') or WinActive('[Class:IEFrame]') or ProcessExists('Taskmgr.exe') Then
    ProcessClose('Taskmgr.exe')    
    run('C:\Windows\System32\rundll32.exe' &amp;amp; $Var)
    EndIf
EndIf
WEnd

#Region Functions
Func _VolumeUp()
    Hotkeyset('{Volume_UP}')
    Send('{Volume_Up 3}')
    Hotkeyset('{Volume_UP}', '_VolumeUp')
EndFunc

Func _VolumeDown()
    Hotkeyset('{Volume_Down}')
    Send('{Volume_Down 3}')
    Hotkeyset('{Volume_Down}', '_VolumeDown')
EndFunc

Func _ScrollLock()
    Send('^{Printscreen}')
    HotKeySet('{SCROLLLOCK}')
    Send('{SCROLLLOCK off}')
    Send('{SCROLLLOCK off}')
    HotKeySet('{SCROLLLOCK}', '_ScrollLock')
EndFunc  

Func _F12()
If $Sound=0 Then
    $Sound=1
Runwait('c:\windows\system32\control.exe mmsys.cpl')
sleep(250)
WinSetTrans('Sound', '', 1)
Hotkeyset('{Volume_UP}')
SendKeepActive('Sound')
Send('{Home}')
Send('{Tab 2}')
Send('{Enter 2}')
Send('{VOLUME_UP 50}')
Hotkeyset('{Volume_UP}', '_VolumeUp')
Else
$Sound=0
Hotkeyset('{Volume_Down}')
Send('{VOLUME_DOWN 25}')
Runwait('c:\windows\system32\control.exe mmsys.cpl')
sleep(250)
WinSetTrans('Sound', '', 1)
SendKeepActive('Sound')
Send('{End}')
Send('{Tab 2}')
Send('{Enter 2}')
Hotkeyset('{Volume_Down}', '_VolumeDown')
EndIf
EndFunc

Func _StopDelayed()
    HotKeySet('{MEDIA_STOP}')
      HotKeySet('{MEDIA_STOP}', '_Lock')
    If $MediaPlayer=1 Then
    $MediaPlayer = 0
Else
    $MediaPlayer = 1
EndIf
    Sleep(500)
    HotKeySet('{MEDIA_STOP}', '_StopDelayed')
EndFunc  

Func _Lock()
    HotKeySet('{MEDIA_STOP}')
     _Pause()
    HotKeySet('{MEDIA_STOP}', '_StopDelayed')
EndFunc

Func _Play()
If $MediaPlayer = 1 then
    HotKeySet('{MEDIA_PlAY_PAUSE}') ; Disable HotKeySet.
    SendKeepActive('[Class:Winamp v1.x]')
    Send('{SPACE}')
    HotKeySet('{MEDIA_PlAY_PAUSE}', '_Fullscreen') ; Enable HotKeySet.
    sleep(500)
    HotKeySet('{MEDIA_PlAY_PAUSE}', '_Play') ; Enable HotKeySet.
Else
    HotKeySet('{MEDIA_PlAY_PAUSE}') ; Disable HotKeySet.
    Send('{MEDIA_PlAY_PAUSE}')
    HotKeySet('{MEDIA_PlAY_PAUSE}', '_Play') ; Enable HotKeySet.
EndIf
EndFunc

Func _Fullscreen()
If $MediaPlayer = 1 then
    SendKeepActive('[Class:Winamp v1.x]')
    Send('{SPACE}')
    Send('{ENTER}')
    HotKeySet('{MEDIA_PlAY_PAUSE}', '_Play') ; Enable HotKeySet.
EndIf
EndFunc      

Func _Next()
If $MediaPlayer = 1 then
    HotKeySet('{MEDIA_NEXT}') ; Disable HotKeySet.
    SendKeepActive('[Class:Winamp v1.x]')
    Send('^{RIGHT}')
    HotKeySet('{MEDIA_NEXT}', '_NextTrack') ; Disable HotKeySet.
    sleep(250)
    HotKeySet('{MEDIA_NEXT}', '_Next') ; EnableHotKeySet.
Else
    HotKeySet('{MEDIA_NEXT}') ; Enable HotKeySet.
    Send('{MEDIA_NEXT}')
    HotKeySet('{MEDIA_NEXT}', '_Next') ; EnableHotKeySet.
EndIf
EndFunc  

Func _NextTrack()
If $MediaPlayer = 1 then
    SendKeepActive('[Class:Winamp v1.x]')
    Send('{PGDN}')
    HotKeySet('{MEDIA_NEXT}', '_Next') ; Disable HotKeySet.
EndIf
EndFunc  

Func _Prev()
If $MediaPlayer = 1 then
    HotKeySet('{MEDIA_PREV}') ; Disable HotKeySet.
    SendKeepActive('[Class:Winamp v1.x]')
    Send('^{LEFT}')
    HotKeySet('{MEDIA_PREV}', '_PrevTrack') ; Disable HotKeySet.
    Sleep(250)
    HotKeySet('{MEDIA_PREV}', '_Prev') ; Disable HotKeySet.
Else
    HotKeySet('{MEDIA_PREV}') ; Enable HotKeySet.
    Send('{MEDIA_PREV}')
    HotKeySet('{MEDIA_PREV}', '_Next') ; EnableHotKeySet.
EndIf
EndFunc  

Func _PrevTrack()
If $MediaPlayer = 1 then
    SendKeepActive('[Class:Winamp v1.x]')
    Send('{PGUP}')
    HotKeySet('{MEDIA_PREV}', '_Prev') ; Disable HotKeySet.
EndIf
EndFunc  

Func _Flash($win)
    If WinActive($win) Then Return 0
    $tFLASHWINFO = DllStructCreate('uint;hwnd;dword;uint;dword')
    DllStructSetData($tFLASHWINFO, 1, 20)
    DllStructSetData($tFLASHWINFO, 2, WinGetHandle($win))
    $a = DllCall('user32.dll', 'int', 'FlashWindowEx', 'ptr', DllStructGetPtr($tFLASHWINFO))
    Return $a[0]
EndFunc

Func Taskbar($Taskbar)
If $Taskbar=1 Then
    $GUITaskBar = WinGetHandle($TaskbarGUI)
    _WinAPI_SetWindowLong($GUITaskBar, $GWL_Exstyle, 0x04000000)
    WinSetOnTop('[CLASS:Shell_TrayWnd]', '', 1)
    WinSetState($TaskbarGUI, '', @SW_HIDE)
    ControlShow('','', WinGetHandle('[CLASS:Button]'))
    WinSetTrans('[Class:Shell_TrayWnd]', '', 255)
Else    
    ControlHide('','', WinGetHandle('[CLASS:Button]'))
    WinSetTrans('[Class:Shell_TrayWnd]', '', 0)
    WinSetState($TaskbarGUI, '', @SW_SHOWMINIMIZED)
    Winflash($TaskbarGUI, '', 2, 25)
    $UIRun=1
EndIf
EndFunc

Func TurnOff()
    If @ExitMethod = 4 Then
    Else
    winmove('[Class:tSkMainForm]', '', -1920, 511, 220, 570,1)
    winmove('[Class:MSBLWindowClass]', '', -1920, 0, 220, 510,1)
    winmove('Friends', '', 3620, 0, 220, 1080,1)
    WinSetTrans('[Class:Shell_TrayWnd]', '', 255)
    ControlShow('','', WinGetHandle('[CLASS:Button]'))
    ControlShow('Program Manager', '', '[CLASS:SysListView32; INSTANCE:1]')
    WinSetTrans('[CLASS:WorkerW; INSTANCE:1]', 'FolderView', 255)
    $AltMsn = WinGetHandle('[CLASS:MSBLWindowClass]')
    $AltSkype = WinGetHandle('[CLASS:tSkMainForm]')
    $AltMedia = WinGetHandle('[CLASS:WMPlayerApp]')
    $AltSteam = WinGetHandle('Friends')
    _WinAPI_SetWindowLong($AltMsn, $GWL_Exstyle, 0x04000000)
    _WinAPI_SetWindowLong($AltSkype, $GWL_Exstyle, 0x04000000)
    _WinAPI_SetWindowLong($AltMedia, $GWL_Exstyle, 0x04000000)
    _WinAPI_SetWindowLong($AltSteam, $GWL_Exstyle, 0x04000000)
EndIf
EndFunc
        
Func Dimmed($Dimmed)
If $Dimmed = 1 and $Flash=0 and $KMPMain=0 Then
    If WinExists('LeftScreen') Then
    Else
    $LeftScreen = GUICreate('LeftScreen', @DesktopWidth, @DesktopHeight, -1920, 0, _
    BitOR($WS_CLIPSIBLINGS, $WS_CLIPCHILDREN, $WS_POPUP), _
    BitOR($WS_EX_TOPMOST, $WS_EX_TRANSPARENT, $WS_EX_TOOLWINDOW, $WS_EX_LAYERED))
    GUISetBkColor(0x000000)
    GUISetState(@SW_SHOW)
    WinSetTrans($LeftScreen, '', 150)
    EndIf

    If WinExists('RightScreen') Then
    Else
    $RightScreen = GUICreate('RightScreen', @DesktopWidth, @DesktopHeight, 1920, 0, _
    BitOR($WS_CLIPSIBLINGS, $WS_CLIPCHILDREN, $WS_POPUP), _
    BitOR($WS_EX_TOPMOST, $WS_EX_TRANSPARENT, $WS_EX_TOOLWINDOW, $WS_EX_LAYERED))
    GUISetBkColor(0x000000)
    GUISetState(@SW_SHOW)
    WinSetTrans($Rightscreen, '', 150)
    EndIf
Elseif $Flash=1 or $KMPMain=1 then
    Else
    GUIDelete($RightScreen)
    GUIDelete($LeftScreen)
EndIf    
EndFunc
#Endregion Functions
Edited by IanN1990

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hire is some feedback you may want to consider. Please do, its important.

I would like to point out that your coding style is rubbish, no offense...just pointing this out.

When coding, especially big projects, you should split your code into separate modules so you can edit your code more easily. Basically into chunks separated with comments, for example see this code, its still not that great example but I cant find better now:

Second, you have 0 comments in your code. This is a fatal flaw. You need to comment your code, explain what function or code piece does what.

This is crucial when trying to mod your code later. You want to look at the code & then instantly know where is the part you want to modify.

You also need debugging, basically consolewrite everything you are outputting, so if shit happens & you screw at some point you see in the console, that the output is not what its supposed to be & you instantly know where is the problem.

Debugging can take days weeks, or you may even need to rewrite the whole code to get rid of the problem.

Lets summarize:

0) Planning stage is very important , always write down what your program should do & how etc, prior starting to code something.

1) make your code look beautiful

2) add plenty comments

3) separate your code with comments or lines

3) add debugging

Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Not to sound rude but most of those things doesn't affect the performance, once a script is complied all comments are removed etc. Though i agree planning can greatly help improve the effectiveness of something ( but my this project started as something small and grown into something very big ego the bad planning), i have gone though it twice now trying to make it better "removing over 400-500 lines and >10 locals while maintaining the same functionality" i was more after ideas or if my coding style is ineffective

IE

If A then

Endif

If B then

endif

is less effective then

If A then

elseif B then

endif

As the first one runs both every time, even if b is dependent on A whereas the second only runs the If once.

As for comments, i edit or add to the script almost every day so i understand what is going on :) that being said i guess its understandable if i posted this online others would find the comments useful ^^

Edited by IanN1990

Share this post


Link to post
Share on other sites

IanN1990,

Perfectly understandable, most spahgetti is made from the "simple" little pgm that gets added onto ad infinatum!

I am assuming that this is your first programming language based on the lack of structure (not a criticism, just an observation). As such, I agree with goldenix's comments, although I might have found another way to phrase them.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

IanN1990,

Adding another post because the goofy editor is mashing the text.

As for comments, i edit or add to the script almost every day so i understand what is going on

Sooner or later you will have moved on to another task and then come back to this...what will you find?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

IanN1990,

Please note that you yourself asked for comments about your coding style. So don't get surprised if someone gives firm opinion on it. Don't dismiss its value by saying it's not important either.

I'll be the third to point it out: your "style" is terrible.

Tidy your code. Modularize it decently, using well defined functions accepting parameters and returning results, checking for and reporting errors as needed.

I've zero idea what your program does or intends to do and, sincerily, I've no incentive to start looking in such guts.

Now you confuse "effective" and "efficient". Both of your sketch If constructs are effective and efficient in the general case. They simply don't have the same meaning. I.e. the keyword here is "appropriate".


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

i didn't say i was going to dismiss it out of hand, trust me i would love to go though all 800 lines making it tidy to the standards of goldnexis but that takes allot of time and i would rather spend the time adding new functions to it rather then adding comments to code that already works.

i was more interested in the coding performance itself rather then the extras. Every 500 MS (which is quite long in my view to help avoid CPU low) it runs my script checking though every IF, i have gone though it to make sure no code is run unless needed "ie the whole check tasbar which is prob 50 Ifs, will only run 1/2 per run". That is more what i wanted this focus on this topic around, how i can improve the performance of the code to use less cpu :)

*PS looking at the OP though i should of put more stress on coding advice in terms of performance rather then style. As looking on this forums every person has their own style when it comes to how code should look and what looks nice. As my code is edited almost daily for personal use and not long-term "ie in 2 years picking it up and editing it" then needing correct commenting is not needed.

Edit also for some reason Autoit removed all the spaces from the code, also is my style really that bad?? ;) I have the variables at the top, different code separated with some commented titles and functions at the bottom XD

P.SS

One thing i am glad to find from reading goldnexis post though is the "pink comments" :D

#Region ### START Code ### Form=

#EndRegion ### END Code ###

Edited by IanN1990

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

i didn't say i was going to dismiss it out of hand, trust me i would love to go though all 800 lines making it tidy to the standards of goldnexis but that takes allot of time and i would rather spend the time adding new functions to it rather then adding comments to code that already works.

P.SS

One thing i am glad to find from reading goldnexis post though is the "pink comments" ;)

#Region ### START Code ### Form=

#EndRegion ### END Code ###

I understand you. And I dont mean for you to go through code & add comments. I meant more like, what you should concentrate on, in the future.

For example I learned it the hard way, having tons of folders filled with small, medium, big script snippets to automate various stuff, to make my life easier turned out to be a nightmare.

I dont know what most of my code does, because of the lack of commentray & structure.(that is in the past now :)

It took me years to understand that the basis of coding is planning, structuring the code & debugging.

I have found that tidying my code does make it go faster, because it allows me to have a better overview & this lets me write the code in a more simplistic manner. As result it gets more efficient & simple to understand.

Following the proper coding path, will make your life way easier & it will take less time coding & debugging later on.

Regarding pink comments, they are also useful, because it adds color variety.

For example say you have 10 forms hidden inside various functions. Now, if you go through the code & see the pink stuff (Its actually purple code...) , And you instantly know there is a form.

You did well asking for advise. 1 Head is good, 2 is better.

Cheers.

Edit, you asked about sleeps, go with 50, see if it slows your code down, you can even go with 10 milliseconds. In case you havent noticed autoit seems to be quite CPU friendly. From I remember using VB, it used 30 times more resource power than autoit after I compiled my VB script to loop 1 simple code line.

Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

well if i was to use sleep(50) it uses 6 cpu :) which is why i use sleep(500)

Share this post


Link to post
Share on other sites

6 CPUs ?

AutoIt is single-threaded!


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Now u see why i have been so focused on performance, Which is why i dont understand its using so much. There are lots of checks "if this exists, if that exists" but none of them run unless it does exist. So why would it be using 6 CPU ? It would just run though going "is a there, nope, is b there nope" .

Edit though i think is should get an achievement for breaking autoit :)

Edited by IanN1990

Share this post


Link to post
Share on other sites

Haha, that's 6%


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

and 6% isn't alot ??

Share this post


Link to post
Share on other sites

First it's a statistical rough value. Then it's 6% _only_. When stuff eats 73% there are legitimate reasons to dig further, but for a stock PC powered by a multi-core CPU, 6% of one core is hardly noticeable to the average user. Translated in equivalent time terms, how would you make the difference between a plain second and 940 ms, honestly ?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Well that's why i am considered. As my CPU is a powerful one and my script will prob get better so if its already using 1 % CPU on 500 MS which is why i am looking for ways to decrease it. I have gone though my code again removing un-needed code and making sure IFs are only ran if needed but i cant find any ways to make it more effective.

Edited by IanN1990

Share this post


Link to post
Share on other sites

Yep, the current code box decided to eat tabs and spaces instead of chocolate toffees, go figure. I'd do it the other way round.

1% is probably not going to decrease significantly, whatever tweeks you apply to you long code.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

6% is negligable at best. To compare, typing in a Word document can consume 3-4% on a quad-core CPU, sending an email as much as 10% if attachments are included. I'd personally be more concerned if your app was consuming a large amount of RAM than 6% of CPU cycles.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

perhaps but those things are not run 24/7 :) if my pc turns on so does my script, which is why i am really making a effort to make it as effective as possible ;)

Share this post


Link to post
Share on other sites

perhaps but those things are not run 24/7 :) if my pc turns on so does my script, which is why i am really making a effort to make it as effective as possible ;)

I might have a solution for you. If you dont need your program to launch with pc & then instantly start using it. For example make your Pc boot up & then after say 1 minute you launch your script.

Basically you make launcher that will launch your program 1 minute after your computer starts. Might decrease startup time.


My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

well i already have something like that in effect :) but thanks for the suggestion

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
Sign in to follow this  
Followers 0