Sign in to follow this  
Followers 0
IanN1990

[Solved] Small Question about performance

20 posts in this topic

#1 ·  Posted (edited)

Heya,

When is started Auto it was just a small thing so performance didn't really matter. Now my personal system.exe is entering over 500 lines of code :D.

It uses If statements check for effects and run actions accordingly, mousepos checks *to show programs or startbar* and hotkeys.

Now it uses a sleep(50) in the while, to not take all up the cpu "when i check task manger its normally on 00 or 01" but still acts fast.

So my question is, there is a computering standard or way of improving performance ?

Edited by IanN1990

Share this post


Link to post
Share on other sites



The way to improve performance is

  • Identify if performance improvement is necessary. If your script runs fast enough (means your users are happy with the performance) leave it alone (never change a running system)
  • Measure your current performance. Identify what to measure (overall performance, file I/O ...)
  • Identify the most expensive operations of your script
  • Try to improve one of these operations
  • Measure performance improvement
  • Improve next operation

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

It really depends on the nature of your script, but some of the best practices I try to adhere to are the following:

1. Declare variables outside of a loop.

2. Try to create arrays using index 0 as the total number of items. (I've been told that the larger the array the slower Ubound() can be.)

3. Use TimerInt/TimerDiff instead of Sleep, as this just pauses the Script. But with using TimerInt/TimerDiiff in a loop I can also watch (for example) when the $GUI_EVENT_CLOSE message is intercepted by GUIGetMsg().

4. Declare variables in the correct scope.

5. I'm sure more examples will come to mind ...

Note: Just because I do this doesn't mean everyone else does.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

IanN1990,

Bowmore's Profiler worked very well showing you which parts of your script were taking the most time and so which were worth optimising. I have not used it for a while so it might need updating, but it proved useful when I did. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

In my opinion TimerInt/Timerdiff doesn't help you to reduce CPU consumption. You just start a timer and measure the elapsed time. You need to use "Sleep".

I think what guinness means is AdlibRegister.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

@Melba23 Thanks for the link i shall have to try that out tool later on :D

@Guinness Thanks for TimerInit over sleep, something like is really useful :oops: "like using hotkeys over Keypresses"

Edit* First time round i used "_Timer_Init" instead of "TimerInit" which is why the cpu was 25, was my silly mistake :rip:

Edited by IanN1990

Share this post


Link to post
Share on other sites

I'm a bit curious. Could you please post the code you use with TimerInit/TimerDiff in a loop without using all CPU?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I remembered that AutoIt itself avoids too much CPU consumption. After some searching/reading I found this:

Basic MessageLoop Format

The general layout of MessageLoop code is:
While 1
  $msg = GUIGetMsg()
  ...
  ...
WEnd

Usually a tight loop like the one shown would send the CPU to 100% - fortunately the GUIGetMsg function automatically idles the CPU when there are no events waiting. Do not put a manual sleep in the loop for fear of stressing the CPU - this will only cause the GUI to become unresponsive.

In a loop where you have a GUIGetMsg statement an additional Sleep statement will SLOW DOWN your script!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

water makes a valid point, it's one of those things you have to ask yourself do you want performance i.e. low CPU, RAM VS. efficiency. For example using Sleep for 1 minute is probably not a smart move when using GUI's and waiting for button clicks etc...

Example as requested by IanN1990:

_Example_1()
_Example_2()

Func _Example_1()
    ConsoleWrite("Started: _Example_1()" & @LF)
    Local $iTimerInt = TimerInit()
    While 1
        Sleep(10)
        If TimerDiff($iTimerInt) > 300 Then ; Greater than 300ms.
            ExitLoop ; Exit the loop.
        EndIf
    WEnd
    ConsoleWrite("300ms elapsed." & @LF)
EndFunc   ;==>_Example_1

Func _Example_2()
     ConsoleWrite("Started: _Example_2()" & @LF)
     Sleep(300)
     ConsoleWrite("300ms elapsed." & @LF)
EndFunc   ;==>_Example_2
Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Now it uses a sleep(50) in the while, to not take all up the cpu "when i check task manger its normally on 00 or 01" but still acts fast.

way of improving performance ?

Decrease Sleep(50) to Sleep(10) or something like this ...

Also post your code to get more help.

Share this post


Link to post
Share on other sites

Func _Example_2()
    ConsoleWrite("Started: _Example_2()" & @LF)
    While 1
        Sleep(300)
        ExitLoop
    WEnd
    ConsoleWrite("300ms elapsed." & @LF)
EndFunc   ;==>_Example_2
Why do you use a While in your second example? This should be enough.

Func _Example_2()
    ConsoleWrite("Started: _Example_2()" & @LF)
    Sleep(300)
    ConsoleWrite("300ms elapsed." & @LF)
EndFunc   ;==>_Example_2

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Hmm well my code is rather big, but mostly copy/paste of functional points with different names :D so i could paste those points and get ur view if they r ineffective or not. All of these are within the main While 1, Sleep(50), Wend

A. When steam launches a game, it hides the ulgy "steam is launching game" window

WinSetState('- Steam','',@SW_HIDE)

B. Checks to see if any steam chat window is hidden, and restores it

$state = WinGetState("- Chat", "")
If BitAnd($state, 16) Then
WinSetState("- Chat","",@SW_RESTORE)
EndIf

C. Shows hides taskbar depending on mouse location

$pos = MouseGetPos()
if $pos[0] >= 1921 and $pos[1] <=2 Then
$active=1
ElseIf $pos[0] <= 3840 and $pos[1] >=45 Then
$active=0
EndIf

if $active=1 and $on=0 then
$on=1
sleep(125)
$pos = MouseGetPos()
if $pos[0] >= 1921 and $pos[1] <=1 Then
_ShowTaskBar(0)
EndIf
endif
$state = WinGetState("[Class:TaskListThumbnailWnd]", "")
if WinActive("Start menu") or WinActive("[Class:TaskListThumbnailWnd]") or WinActive("{Class:NotifyIconOverflowWindow]") or  BitAnd($state, 2) Then
$status=1
Else
$status=0
EndIf
if $active=0 and $on=1 and $status=0 then
$on=0
sleep(550)
_ShowTaskBar(1)
endif

D. Checks if a process is active, and runs a exe once until that exe is closed

;KMPlayer Media Player Code
if ProcessExists("KMPlayer.exe") Then
$KmplayerActive=1
else
$KmplayerSecondary=0
$KmplayerActive=0
$MediaPlayer=0
EndIf
if $KmplayerActive=1 and $KmplayerSecondary=0 then
Run ("C:Program Files (x86)Scripts00¦ MiscellaneousMicrosoftKmplayer flash.exe")
$KmplayerSecondary=1
EndIf
Edited by IanN1990

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I would advise not to mention the 'G' word in the future. I haven't reported because it doesn't look as though you're breaking the rules, but just for the future.

Why do you use a While in your second example? This should be enough.

Purely for the purposes of the example, though looking back probably not one of the best to showcase Sleep. You're right water. Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

hm ok :D i have read the site rules and i didn't think what i said was wrong ? as its just hiding a popup ? If i am mistaken i do apologize

That aside, is my coding ok ? have i left anything in there that could be removed or improved for better performance ?

Edited by IanN1990

Share this post


Link to post
Share on other sites

Spending the whole cpu just on a TimerDiff() seems like a waste.

Func _Example_1()
    ConsoleWrite("Started: _Example_1()" & @LF)
    Local $iTimerInt = TimerInit()
    While 1
        Sleep(10)
        If TimerDiff($iTimerInt) > 300 Then ; Greater than 300ms.
            ExitLoop ; Exit the loop.
        EndIf
    WEnd
    ConsoleWrite("300ms elapsed." & @LF)
EndFunc   ;==>_Example_1

That's better.

Share this post


Link to post
Share on other sites

Today is clearly not my day. Thanks AdmiralAlkex, I've updated the previous example.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

hell of some code there :D i used sleep 1, with timer 1 vs sleep 2. The timer was using 0 cpu while the sleep(2) was using 2/3 cpu :oops: very impressive

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

It was requested I review this thread because of the mention of Steam and launching a game. I see nothing wrong with the thread. This is about hiding/showing Steam windows from what I gather in a quick skim.

Edited by Valik

Share this post


Link to post
Share on other sites

If you're monitoring a whole system, you wanna look into events, callbacks and hooking - instead of polling every single case you might need. That is pretty much programming 101.


Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

I have no idea what any of that means :oops: but i did go though my code and reduce it from around 500 lines+ with 20+ variables to around 200 lines and 7 variables :rip:

#NoTrayIcon
#include <Misc.au3>
#Include <WinAPI.au3>
Opt('WinTitleMatchMode', 2 )
HotKeySet("{MEDIA_PlAY_PAUSE}", "_Play")
HotKeySet("{MEDIA_NEXT}", "_Next")
HotKeySet("{MEDIA_PREV}", "_Prev")
HotKeySet("{MEDIA_STOP}", "_Stop")
HotKeySet("{VOLUME_MUTE}", "_Mute")
HotKeySet("{SCROLLLOCK}", "_ScrollLock")
HotKeySet("{PAUSE}", "_Pause")
HotKeySet("^{F12}", "_F12")

local $Sound=0
local $MediaPlayer=0
local $KMPlayer=0
local $ChatHover
local $TaskbarHover
local $Taskbar
local $TaskbarExtra=0

Global Const $WM_QUERYENDSESSION = 0x0011
GUICreate('')
GUIRegisterMsg($WM_QUERYENDSESSION, 'WM_QUERYENDSESSION')

While 1
sleep(100)

;Hide Steam Lauching
WinSetState('- Steam','',@SW_HIDE)

;Show Chat Messages
$Steam = WinGetState("- Chat", "")
$MsN = WinGetState("[Class:TConversationForm]", "")
$Skype = WinGetState("[Class:IMWindowClass]", "")
If BitAnd($Steam, 16) Then
    WinSetState("- Chat","",@SW_RESTORE)
elseif BitAnd($MsN, 16) Then
    WinSetState("[Class:TConversationForm]","",@SW_RESTORE)
ElseIf BitAnd($Skype, 16) Then
    WinSetState("[Class:IMWindowClass]","",@SW_RESTORE)
EndIf

;Show Taskbar
$pos = MouseGetPos()
if $pos[0] >= 1921 and $pos[1] <=2 Then
    $TaskbarHover=1
ElseIf $pos[0] <= 3840 and $pos[1] >=45 Then
    $TaskbarHover=0
EndIf

if $TaskbarHover=1 and $Taskbar=0 then
    $Taskbar=1
sleep(75)
$pos = MouseGetPos()
if $pos[0] >= 1921 and $pos[1] <=1 Then
    _ShowTaskBar(0)
EndIf
endif

$Thumbnail = WinGetState("[Class:TaskListThumbnailWnd]", "")
$Nofication = WinGetState("[Class:NotifyIconOverflowWindow]", "")
if WinActive("Start menu") or WinActive("[Class:TaskListThumbnailWnd]") or BitAnd($Thumbnail, 2) or BitAnd($Nofication, 2)  Then
    $TaskbarExtra=1
Else
    $TaskbarExtra=0
EndIf

if $TaskbarHover=0 and $Taskbar=1 and $TaskbarExtra=0 then
    $Taskbar=0
sleep(75)
_ShowTaskBar(1)
Endif

;Chat Hover
$pos = MouseGetPos()
if $pos[0] <= -1880 and $pos[1] <=360 Then
    sleep(75)
    $pos = MouseGetPos()
    if $pos[0] <= -1880 and $pos[1] <=360 and $ChatHover=0 Then
        $ChatHover=1
        WinActivate("Windows Live Messenger")
    EndIf
elseif $pos[0] <= -1880 and $pos[1] <=720 and $pos[1] >=360 Then
    sleep(75)
    $pos = MouseGetPos()
    if $pos[0] <= -1880 and $pos[1] <=720 and $pos[1] >=360 and $ChatHover=0 Then
        $ChatHover=1
        WinActivate("Friends")
    EndIf
elseif $pos[0] <= -1880 and $pos[1] >=720 and $pos[1] <=1080 Then
    sleep(75)
    $pos = MouseGetPos()
    if $pos[0] <= -1880 and $pos[1] >=720 and $pos[1] <=1080 and $ChatHover=0 Then
        $ChatHover=1
        WinActivate("Skype™ - lann1990")
    EndIf
Else
    If $pos[0] >= -1700 and $ChatHover=1 Then
    $ChatHover=0
    WinSetState("Windows Live Messenger","",@SW_MINIMIZE)
    WinSetState("Skype™ - lann1990","",@SW_MINIMIZE)
    WinSetState("Friends","",@SW_MINIMIZE)
Endif
EndIf

;KMPlayer Media Player Code
if ProcessExists("KMPlayer.exe") Then
    if $KMPlayer=0 then
    $KMPlayer=1
    Run ("C:Program Files (x86)Scripts00¦ MiscellaneousMicrosoftKmplayer flash.exe")
    EndIf
else
if  $KMPlayer=1 then
    $KMPlayer=0
EndIf
EndIf
WEnd

; Functions
Func _ScrollLock() ; Add here what you want to happen when you push the SCROLLLOCK key.
    send("^{Printscreen}")
    HotKeySet("{SCROLLLOCK}") ; Disable HotKeySet.
    Send("{SCROLLLOCK off}") ; Two Sends() seem to work.
    Send("{SCROLLLOCK off}")
    HotKeySet("{SCROLLLOCK}", "_ScrollLock") ; Enable HotKeySet.
EndFunc   ;==>_ScrollLock

Func _Pause() ; Add here what you want to happen when you push the SCROLLLOCK key.
    RunWait('wscript.exe "C:Program Files (x86)Scripts00¦ MiscellaneousMicrosoftOperating SystemLogOff.vbs"')
EndFunc   ;==>_ScrollLock

Func _F12()
if $Sound=0 Then
    $Sound=1
    run("C:Program Files (x86)Scripts00¦ MiscellaneousMicrosoftWireless.exe")
else
    $Sound=0
    run("C:Program Files (x86)Scripts00¦ MiscellaneousMicrosoftMain.exe")
EndIf
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(1000)
    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 _Stop() ;
if $MediaPlayer=1 Then
        $MediaPlayer = 0
Else
        $MediaPlayer = 1
EndIf
EndFunc  

Func _Mute() ;
    HotKeySet("{VOLUME_MUTE}") ; Disable HotKeySet.
    Send("{VOLUME_MUTE}")
    HotKeySet("{VOLUME_MUTE}", "_Lock") ; Disable HotKeySet.
    Sleep(250)
    HotKeySet("{VOLUME_MUTE}", "_Mute") ; Disable HotKeySet.
EndFunc  

Func _Lock() ;
    HotKeySet("{VOLUME_MUTE}") ; Disable HotKeySet.
    Send("{VOLUME_MUTE}")
    RunWait('wscript.exe "C:Program Files (x86)Scripts00¦ MiscellaneousMicrosoftOperating SystemLogoff.vbs"')
    HotKeySet("{VOLUME_MUTE}", "_Mute") ; Disable HotKeySet.
EndFunc   

Func WM_QUERYENDSESSION($hWnd, $iMsg, $wParam, $lParam)
run('wscript.exe "C:Program Files (x86)Scripts00¦ MiscellaneousMicrosoftOperating SystemLogOff3.vbs"')
ProcessClose("Steam.exe")
processClose("msnmsgr.exe")
EndFunc  

Func _ShowTaskBar($fShow)
Local $hTaskBar
If @OSVersion = "WIN_VISTA" or @OSVersion = "WIN_2008" or @OSVersion = "WIN_7" Then _ShowStartButton($fShow)
$hTaskBar = _WinAPI_FindWindow("Shell_TrayWnd", "")
If $fShow=0 Then
_WinAPI_ShowWindow($hTaskBar, @SW_SHOW)
Else
_WinAPI_ShowWindow($hTaskBar, @SW_HIDE)
EndIf
EndFunc ;==>_ShowTaskBar
Func _ShowStartButton($fShow )
Local $hTaskBar, $hStartButton
If @OSVersion = "WIN_VISTA" or @OSVersion = "WIN_2008" or @OSVersion = "WIN_7" Then
$hStartButton = _WinAPI_FindWindow("Button", "Start")
Else
$hTaskBar = _WinAPI_FindWindow("Shell_TrayWnd", "")
$hStartButton = ControlGetHandle($hTaskBar, "", "Button1")
EndIf
If $fShow=0 Then
_WinAPI_ShowWindow($hStartButton, @SW_SHOW)
Else
_WinAPI_ShowWindow($hStartButton, @SW_HIDE)
EndIf
EndFunc ;==>

I am still very new with autoit, kinda just picked it up and started writing scripts to improve how i use my computer :D

Edited by IanN1990

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