
jsteng
Active Members-
Posts
26 -
Joined
-
Last visited
Everything posted by jsteng
-
Hi, I have been plagued by my wife and kids leaving the computer on overnight. No matter how many times I reprimand them, they still oftentimes forget to turn off the machine. And because all our files (My Document folder and Desktop) are stored on a NAS, Window's auto-hibernate does not work when MS Word/Excel has an open network file... THIS had gone for YEARS! So I happened to find some Autoit codes in this forum and combined some of them to make a Force Hibernate: Opt("TrayIconHide", 1) ; #FUNCTION#;=============================================================================== ; ; Name...........: _Timer_GetIdleTime() ; Description ...: Returns the number of ticks since last user activity (i.e. KYBD/Mouse) ; Syntax.........: _Timer_GetIdleTime() ; Parameters ....: None ; Return values .: Success - integer ticks since last (approx. milliseconds) since last activity ; Failure - Sets @extended = 1 if rollover occurs (see remarks) ; Author ........: PsaltyDS at http://www.autoitscript.com/forum ; Modified.......: v1.0.0 -- 03/20/2008 First version ; v1.0.1 -- 06/11/2008 Fixed bug when idle time = 0ms ; Remarks .......: The current ticks since last system restart will roll over to 0 every 50 days or so, ; which makes it possible for last user activity to be before the rollover, but run time ; of this function to be after the rollover. If this happens, @extended = 1 and the ; returned value is ticks since rollover occured. ; Related .......: _CheckIdle() ; Link ..........; ; Example .......; Yes ; ;;========================================================================================== Func _Timer_GetIdleTime() ; Get ticks at last activity Local $tStruct = DllStructCreate("uint;dword"); DllStructSetData($tStruct, 1, DllStructGetSize($tStruct)); DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($tStruct)) ; Get current ticks since last restart Local $avTicks = DllCall("Kernel32.dll", "int", "GetTickCount") ;Return time since last activity, in ticks (approx milliseconds) Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2) If $iDiff >= 0 Then ; Normal return Return $iDiff Else ; Rollover of ticks counter has occured Return SetError(0, 1, $avTicks[0]) EndIf EndFunc ;==>_Timer_GetIdleTime ;=============================================================================== ; ; Description: Sets a wakeup time to wake it up if the system / computer is hibernating or standby ; Parameter(s): $Hour - Hour Values : 0-23 ; $Minute - Minutes Values: 0-59 ; $Day - Days Values : 1-31 (optional) ; $Month - Month Values : 1-12 (optional) ; $Year - Year Values : > 0 (optional) ; ; Requirement(s): DllCall ; Return Value(s): On Success - 1 ; On Failure - 0 sets @ERROR = 1 and @EXTENDED (Windows API error code) ; ; Error code(s): [url=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/system_error_codes.asp]http://msdn.microsoft.com/library/default....error_codes.asp[/url] ; ; Author(s): Bastel123 aka Sebastian ; Note(s): - ; ;=============================================================================== Func _SetSuspend($mode=true,$force=true) $result = DllCall("PowrProf.dll", "long", "SetSuspendState", "long",$mode, "long",$force, "long", false) EndFunc GLOBAL $MaxIdleTime = 30 * 60 * 1000 local $idle = 0 Global $x = @DesktopWidth - 20 Global $y = @DesktopHeight - 10 func Print($text) ToolTip($text, $x, $y, "", 0, 2) endfunc While 1 if _Timer_GetIdleTime() > $MaxIdleTime then Print ("IDLE") _SetSuspend() while _Timer_GetIdleTime() > $MaxIdleTime sleep(1000) wend endif Print(stringformat("%0.0f", _Timer_GetIdleTime()/1000)) sleep(1000) wend So now, how do i make this script autorun everytime windows is loaded up? THanks!
-
Lastly, according to documents: Considering the file was renamed or deleted, SHOULD I still perform FileClose($FileHandle)???
-
I have a question with regards to FileOpen. Given: A text file @MyDocumentsDir & "\book keeper\logs\logs.txt" is used by another app; but I can open and read it. $FileHandle = FileOpen(@MyDocumentsDir & "\book keeper\logs\logs.txt") The code was successfully executed. something happened afterwards: logs.txt was renamed and a new logs.txt was created, or simply deleted a: Will $FileHandle still point to the renamed file? or b: Will $FileHandle point to the new logs.txt file? or c: Will $FileHandle point to nothing at all? thks
-
Hi Attached is a screenshot of a popup window (from a video recording app called bandicam) I need to relocate/move. According to Autoit's Window Info, it is a CLASS:TARGETRECT. I tried using this script but failed. if WinExists("[CLASS:TARGETRECT]") then ;bandicam's small window local $hwd = WinGetHandle("[CLASS:TARGETRECT]") local $xyz = WinGetPos($hwd) WinMove( $hwd, "", 100, 100 ) ;ControlMove( $hwd, "", '', 100, 100 ) EndIf I appreciate if you could help me debug. thanks.
-
Help detecting TCP-IP disconnections
jsteng replied to jsteng's topic in AutoIt General Help and Support
Honestly, the solution was to use different method instead of TCP IP to send data between machines, albeit NOT elegant but I less hassle. But with respect to my original query, I still have problems detecting TCP-IP disconnection using TCPRecv. I was very frustrated so I simply switched method. If anyone cares to debug: #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.8.1 (Or greater) Author: Ken Piper Script Function: Template multi-client server base code. Use as a base for making an efficient server program. This base will just accept connections and echo back what it receives, and kill the connection if it is dead or inactive for x seconds. It will not do any other work, that must be added seperately! #ce ---------------------------------------------------------------------------- #include <Array.au3> TCPStartup() Opt("TCPTimeout", 0) #region ;Safe-to-edit things are below Global $BindIP = "0.0.0.0" ;Listen on all addresses Global $BindPort = 8080 ;Listen on port 8080 Global $PacketSize = 512 ;Max packet size per-check Global $MaxClients = 10 ;Max simultaneous clients #endregion ;Stuff you shouldn't touch is below Global $Listen Global $Clients[1][4] = [[0,0,0,0]] ;[Index][Socket, IP, Timestamp, Buffer] Global $Ws2_32 = DllOpen("Ws2_32.dll") ;Open Ws2_32.dll, it might get used a lot Global $NTDLL = DllOpen("ntdll.dll") ;Open ntdll.dll, it WILL get used a lot OnAutoItExitRegister("ExitProcedure") ;Register this function to be called if the server needs to exit $Listen = TCPListen($BindIP, $BindPort, $MaxClients) ;Start listening on the given IP/port If @error Then Exit 1 ;Exit with return code 1 if something was already bound to that IP and port while 1 local $i local $iSock = TCPAccept($Listen) ;See if anything wants to connect if $iSock <> -1 then $busy = 1 $i = UBound($Clients, 1) ;get the number of current connections if $i >= $MaxClients then ;maxclients reached TCPCloseSocket($iSock) ;drop the new connection else _ArrayAdd($Clients, "0|0|0|0") ;allocate space for new connection $Clients[$i][0] = $iSock ;Set the socket ID of the connection $Clients[$i][2] = TimerInit() ;Set the timestamp for the last known activity timer $Clients[$i][3] = "" ;Blank the recv buffer TCPSend($Clients[$i][0], "Welcome Client #"&$i&@CRLF) endif endif ;This part Checks buffers and do things starting at 1st connection $i = 1 while $i < UBound($Clients,1) ;loop through all clients starting at 1st position local $sRecv = TCPRecv($Clients[$i][0], $PacketSize) ;read from client's connection if $sRecv = "" AND @error < 0 then ;connection error TCPCloseSocket($Clients[$i][0]) ;close the connection _ArrayDelete($Clients, $i) ;delete allocation else $Clients[$i][2] = TimerInit() ;update the activity timer $Clients[$i][3] &= $sRecv ;add data to buffer if StringInStr($Clients[$i][3], @CRLF, 0) then TCPSend($Clients[$i][0], "Echoing line: " & $Clients[$i][3]) ;Echo back the packet the client sent if StringInStr($Clients[$i][3],"?",0) then TCPSend($Clients[$i][0], "UBound($Clients,1): " & UBound($Clients,1) & @CRLF) endif $Clients[$i][3] = '' endif $i += 1 endif wend sleep(10) wEnd Func ExitProcedure() DllClose($Ws2_32) ;Close the open handle to Ws2_32.dll DllClose($NTDLL) ;Close the open handle to ntdll.dll For $i = 1 To $Clients[0][0] ;Loop through the connected clients TCPCloseSocket($Clients[$i][0]) ;Force the client's connection closed Next TCPShutdown() ;Shut down networking stuff EndFunc TCPRecv is not giving me the @error I was hoping for. I tried @error > 0, @error < 0 and @error <> 0, nothing worked. Original script uses a timer to disconnect idle users. I dont want timer to disconnect users. -
please delete found solution
-
StatusBarGetText to get CPU Load
jsteng replied to jsteng's topic in AutoIt General Help and Support
Honestly, I wanted to do two things: Firstly, getting CPU and Memory Load, for the whole machine and not per process. Secondly, investigating StatusBarGetText, for possible use with other scripts. I was wondering why it was not working for task manager. thanks -
Im trying to use this script while 1 $rc = StatusBarGetText(Task Manager,'',2) if @error > 0 then Tooltip('error') else Tooltip($rc) endif sleep(250) wend it is basically the same as the one found in this thread: but StatusBarGetText kept giving me blank. is it due to 10+ years it was no longer valid? thanks
-
How to WinExist('[CLASS:#32770]') with Button1?
jsteng posted a topic in AutoIt GUI Help and Support
Hi, I am writing a script that closes error popups on windows. The error popups always appear as [CLASS:#32770] and thus I wrote this: #RequireAdmin while 1 _CloseErrorPopUps() sleep(100) wend Func _CloseErrorPopUps() if WinExists("[CLASS:#32770]") then local $title = WinGetTitle("[CLASS:#32770]") local $pid = WinGetProcess ( $title ) ControlSend($title, "", "Button1", "{ESC}") ;close the popup tooltip($pid & ' ' & $title) endif endfunc However, I soon realize that some other non-error processes use [CLASS:#32770]. a system service igfxem.exe for instance exists in one of my machine and contains this [class#32770] that could not be closed. My question is: 1. Is there a way to use WinExists to filter only [CLASS:#32770] with Button1? If so how? or 2. Must I use an exhaustive one-by-one approach of listing all the error popups instead? if WinExists('[CLASS:#32770]', 'out of bound error') then . if WinExists('[CLASS:#32770]', 'Autoit Error') then . . . . . thanks. j -
auto3info did the job.... thanks!
-
At the meantime, I am looking at an old thread: wonder if this is what I need
-
using this example script as reference: #include <MsgBoxConstants.au3> Example() Func Example() ; Run Notepad Run("notepad.exe") ; Wait 10 seconds for the Notepad window to appear. Local $hWnd = WinWait("[CLASS:Notepad]", "", 10) ; Set the edit control in Notepad with some text. The handle returned by WinWait is used for the "title" parameter of ControlSetText. ControlSetText($hWnd, "", "Edit1", "This is some text") ; Retrieve the text of the edit control in Notepad. The handle returned by WinWait is used for the "title" parameter of ControlGetText. Local $sText = ControlGetText($hWnd, "", "Edit1") ; Display the text of the edit control. MsgBox($MB_SYSTEMMODAL, "", "The text in Edit1 is: " & $sText) ; Close the Notepad window using the handle returned by WinWait. WinClose($hWnd) EndFunc ;==>Example How do I know "Edit1" is a controlID from Notepad? What are the other controlID used by Notepad? To be more specific, How do I get to know controlID used by a specified window handle from WinList()? I hope I expressed my question properly. many thanks.
-
FileGetSize not working after 2nd use
jsteng replied to jsteng's topic in AutoIt General Help and Support
Sample script that creates log file: #RequireAdmin #include <Date.au3> If Not IsAdmin() Then If @error Then Return MsgBox(16 + 262144, "ERROR!", "Requires to run as Admin.") Exit EndIf Global $logfile = @MyDocumentsDir & "\udit\logs\logs.txt" Global $sLine = "" Global $lFile = FileOpen($logfile,1) Global $logSize = 0 FileSetPos($lFile, 0, 2) ;sets the current read position to the end of the file while 1 FileWrite($lFile, _NowCalc() & '.' & @MSEC & @CRLF) sleep(300) wend -
FileGetSize not working after 2nd use
jsteng replied to jsteng's topic in AutoIt General Help and Support
#RequireAdmin If Not IsAdmin() Then If @error Then Return MsgBox(16 + 262144, "ERROR!", "Requires to run as Admin.") Exit EndIf Global $logfile = @MyDocumentsDir & "\udit\logs\logs.txt" Global $sLine = "" Global $lFile = FileOpen($logfile) Global $logSize = 0 FileSetPos($lFile, 0, 2) ;sets the current read position to the end of the file while 1 $logsize = FileGetSize($logfile) $sLine = FileReadLine($lFile) ToolTip( stringformat("%8d %s", $logsize,$sLine), @DesktopWidth/2, @DesktopHeight-12,"",0,2) sleep(100) wend Said log/text file is not static; it is constantly getting written, about 1-10x per second. And the ToolTip line was printing the new lines written into it but the FileGetSize isnot getting updated. -
I have a running program that continuously write to a text file. My requirement is to have an AutoIt script that constantly fetches this text file's filesize using FileGetSize($logfile) in a loop. All seems working. However, I noticed that FileGetSize is not getting updated at all. It remains constant all throughout. What gives? AutoIt's script is running in admin mode. Is there something I need to do in order refresh this FileGetSize function? FYI: Someone else asked this back in 2013 with no answer to his question. Maybe newer Autoit has an answer? Thanks.
-
Problem with 2-dimensional Array
jsteng replied to jsteng's topic in AutoIt General Help and Support
Curious: Is there an autoit equivalent to Perl's @{$TimeOut[0]}? Or a means of getting the pointer to the 2nd dimension? That way, i can now do uBound( @{$TimeOut[0]} ) -
Problem with 2-dimensional Array
jsteng replied to jsteng's topic in AutoIt General Help and Support
The more I try to solve my multi-dimensional array problem, the more problems I encounter. GLOBAL $TimeOut[8][8], $Text[8], $aTemp $Text[0] = "0" $Text[1] = "1000,3000" $Text[2] = "1000,2000,3000" $Text[3] = "3000" $Text[4] = "2000,3000" $Text[5] = "1000,2000,3000,4000,5000,6000" $Text[6] = "0" $Text[7] = "1000" for $i = 0 to 7 $aTemp = StringSplit( $Text[$i], "," ,2) For $j = 0 To 2 $TimeOut[$i][$j] = $aTemp[$j] Next next ;Simulated _ArrayPush($TimeOut[0],$TimeOut[0][0],0) local $firstItem = $TimeOut[0][0] local $lastIndex = uBound($TimeOut[0])-1 for $i=0 to $lastIndex-1 $TimeOut[0][$i] = $TimeOut[0][$i+1] next $TimeOut[0][$lastIndex] = $firstItem UBOUND will not allow me to check on a multi-dim array... It actually does, but the way I am using above, with the 2nd dimension having different length this will not work: UBOUND($TimeOut,2) Seems that I should just put the data AS a string into the array, and have a lengthly/slower code that will convert it to an array, rotate, put it back as a string... -
Problem with 2-dimensional Array
jsteng replied to jsteng's topic in AutoIt General Help and Support
GLOBAL $TimeOut[8][8], $Text[8], $aTemp $Text[0] = "1000,2000,3000" $Text[1] = "1000,2000,3000" $Text[2] = "1000,2000,3000" $Text[3] = "1000,2000,3000" $Text[4] = "1000,2000,3000" $Text[5] = "1000,2000,3000" $Text[6] = "1000,2000,3000" $Text[7] = "1000,2000,3000" for $i = 0 to 7 $aTemp = StringSplit( $Text[$i], "," ,2) For $j = 0 To 2 $TimeOut[$i][$j] = $aTemp[$j] Next next ;Now how do I do something like this? _ArrayPush($TimeOut[0],$TimeOut[0][0],0) ; I am getting this error with _ArrayPush Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded. I can't do ArrayPush on multi dimensional arrays? (My purpose for the arrayPush is to rotate the data) Is it possible to pass the reference of the 2nd dimension array to a function? If so, How? -
Problem with 2-dimensional Array
jsteng replied to jsteng's topic in AutoIt General Help and Support
I thought I can "wholesale" assign an array into an array to make it 2D Now i understand. many thanks! -
GLOBAL $TimeOut[8][8],$Text[8] $Text[0] = "1000,2000,3000" $Text[1] = "1000,2000,3000" $Text[2] = "1000,2000,3000" $Text[3] = "1000,2000,3000" $Text[4] = "1000,2000,3000" $Text[5] = "1000,2000,3000" $Text[6] = "1000,2000,3000" $Text[7] = "1000,2000,3000" for $i = 0 to 7 $TimeOut[$i] = StringSplit( $Text[$i],",",2) next Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded. How do I assign an Array into an Array using StringSplit?
-
Im trying to do a pixelsearch for a particular pixel color. However, depending on the browser or desktopsize, this pixel changes color ever so slightly: ie, the red component changes by 15 shades, green component changes by 4 shades, and blue component stays the same. If I were to do a Pixelsearch with tolerance set to 16, it will match a lot more pixels - and perhaps wrong pixels. Is there a built-in function or optimized 3rd party dll that I can specify the shade variance per color component?
-
function to convert key to its _IsPressed equivalent.
jsteng replied to jsteng's topic in AutoIt General Help and Support
rest assured this is NOT a keylogger app nor other prohibited apps besides, there are other programming languages that can do that purpose better and easier -
Is there a function that will convert a single key/char used with send to its equivalent keycode used by _IsPressed? ie, $key = "=" $keycode = FUNCTION($key) ;will convert "=" to "BB" send("{"& $key & " down}") _IsPressed($keycode) is true it should work also for the other special characters like SHIFT, CTRL, ALT, SPACE, BACkSPACE... and so on. $key = "SHIFT" $keycode = FUNCTION($key) ;will convert "SHIFT" to "10" send("{"& $key & " down}") _IsPressed($keycode) is true ASC? Or perhaps something that is better/simpler than _IsPressed ie $key = "v" send("{"& $key & " down}") . . FunctionIsPressed($key) is true bottom line, I dont like having to lookup the keycode that is used by IsPressed
-
question with screencapture, pixelchecksum
jsteng replied to jsteng's topic in AutoIt General Help and Support
I sure like what you said. will test it once i got back to office. many thanks -
Best method to test area for color
jsteng replied to undefinedspace's topic in AutoIt General Help and Support
You are trying to search for a color under the mouse for a match within an area 10x10 centered under the mouse shouldnt that always be TRUE? but bootybay wrote it much cleaner. check how he did the error checking vs how ou did it.