Sign in to follow this  
Followers 0
matter

Freeze Process if mouse is active, if inactive for 25 seconds then Resume Process

15 posts in this topic

#1 ·  Posted (edited)

Having a bit of trouble. I went over the code so many times, I thought it out while I was half asleep and wrote it on my Note 2.. Everything seems right but it is not working. from start it just freezes, and stays froze . Please help!!

DIM $MousePos
Dim $MousePosChange
Global $processtoSuspend = "notepad.exe"

While 1
    $MousePos = MouseGetPos()
    sleep (1000)
    $MousePosChange = MouseGetPos ()

                if $MousePos <> $MousePosChange then
                    if ProcessExists ($processtoSuspend) Then _ProcessSuspend(ProcessExists ($processtoSuspend))
                Else

                    $MousePos = MouseGetPos()
                    sleep(25000)
                    $MousePosChange = MouseGetPos()

                        if $MousePos <> $MousePosChange then
                                if ProcessExists ($processtoSuspend) Then _ProcessSuspend(ProcessExists ($processtoSuspend))
                        Else
                                if ProcessExists ($processtoSuspend) Then _ProcessResume(ProcessExists ($processtoSuspend))
                        EndIf

                EndIf

WEnd

Func _ProcessSuspend($process)
$ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $process)
$i_sucess = DllCall("ntdll.dll","int","NtSuspendProcess","int",$ai_Handle[0])
DllCall('kernel32.dll', 'ptr', 'CloseHandle', 'ptr', $ai_Handle)
EndFunc
Func _ProcessResume($process)
$ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $process)
$i_sucess = DllCall("ntdll.dll","int","NtResumeProcess","int",$ai_Handle[0])
DllCall('kernel32.dll', 'ptr', 'CloseHandle', 'ptr', $ai_Handle)
EndFunc
Edited by matter

Share this post


Link to post
Share on other sites



matter,

Welcome to the AutoIt forum. :)

A hint - what does MouseGetPos return? ;)

It returns an array and you cannot compare arrays directly in AutoIt - you have to compare the elements.

;)

And out of interest, why do you want to do this? :huh:

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

I work from home, I have a tripple screen setup, I am going to enable my TV as well for stats only, but do not want the stats to update while im using the PC. so i would like it to see if im not using my mouse. and if not then update stats every second.

I will add msgbox with what MouseGetPos gets to see. 

thanks for the welcome!!!

Share this post


Link to post
Share on other sites

matter,

MsgBox will not display anything as the function returns an array - use _ArrayDisplay. But do not forget #include Array.au3 at the top of the script. ;)

 

update stats every second

That is some update rate! :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

matter,

Welcome to the AutoIt forum. :)

A hint - what does MouseGetPos return? ;)

It returns an array and you cannot compare arrays directly in AutoIt - you have to compare the elements.

;)

And out of interest, why do you want to do this? :huh:

M23

 

ah, msgbox is blank dude >.< your awesome for pointing that out.

Share this post


Link to post
Share on other sites

matter,

MsgBox will not display anything as the function returns an array - use _ArrayDisplay. But do not forget #include Array.au3 at the top of the script. ;)

 

That is some update rate! :D

M23

what are you a physic?  LOL

Share this post


Link to post
Share on other sites

matter,

No, although after 5 years or so my crystal ball does help with some of the more obvious beginner problems. :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

 

Having a bit of trouble. I went over the code so many times, I thought it out while I was half asleep and wrote it on my Note 2.. Everything seems right but it is not working. from start it just freezes, and stays froze . Please help!!

...

 

See :

#include <WinAPIEx.au3>
If _WinAPI_GetIdleTime() > 25000 Then

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

_timer_getidletime is probably easier, if you don't mind for mouse and keyboard presses:

#include <Timers.au3>
While True
    While _Timer_GetIdleTime() < 25000
        ; looping until idle for 25 seconds
        Sleep(1000)
    WEnd

    ; your code to do stat updates
    
    
    
    Sleep (1000)
WEnd





edit: haha, 2 seconds too late :)...well, same basic function, diff udf

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

_timer_getidletime is probably easier, if you don't mind for mouse and keyboard presses:

#include <Timers.au3>
While True
    While _Timer_GetIdleTime() < 25000
        ; looping until idle for 25 seconds
        Sleep(1000)
    WEnd

    ; your code to do stat updates
    
    
    
    Sleep (1000)
WEnd





edit: haha, 2 seconds too late :)...well, same basic function, diff udf

aaahh thanks dude!!!! this worked.. but paused for 50 seconds?? not sure why

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

are you sure about that :)...try with this (don't move/press anything)

#include <Timers.au3>
While True
    $iTimer = TimerInit()
    While _Timer_GetIdleTime() < 25000
        ; looping until idle for 25 seconds
        Sleep(1000)
    WEnd

    ; your code to do stat updates
    MsgBox(1,1,TimerDiff($iTimer)/1000)


    Sleep (1000)
WEnd

my message box showed very close to 25 seconds (which it will never be exact, since it takes a few seconds to start the script, and impossible to "time" the idle time...pluss the sleeps can cause the idle time to go over 25 seconds, but it should be around 25 +1 second

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

are you sure about that :)...try with this (don't move/press anything)

#include <Timers.au3>
While True
    $iTimer = TimerInit()
    While _Timer_GetIdleTime() < 25000
        ; looping until idle for 25 seconds
        Sleep(1000)
    WEnd

    ; your code to do stat updates
    MsgBox(1,1,TimerDiff($iTimer)/1000)


    Sleep (1000)
WEnd

my message box showed very close to 25 seconds (which it will never be exact, since it takes a few seconds to start the script, and impossible to "time" the idle time...pluss the sleeps can cause the idle time to go over 25 seconds, but it should be around 25 +1 second

ah yea im sure dude.. i tested it on local and VM and still about 50 secs.... but! ill take it!!! thanks soo much bro

Share this post


Link to post
Share on other sites

that's so weird...put the idletime < 12500 :)

One last question tho. Why the $iTimer? is it doing anything? when i compile it gives me an error saying "

-### Obfuscation Error: Found DllCallbackRegister() statement using unsolvable Func, which will/could lead to problems running your obfuscated script.
>### current Func: _Timer_SetTimer
C:Program FilesAutoIt3includeTimers.au3(275,1) Warning for line:$hCallBack = DllCallbackRegister($sTimerFunc, "none", "hwnd;int;uint_ptr;dword") 

Share this post


Link to post
Share on other sites

Don't use any of the /strip options without using the wrapper directives to skip obfuscating certain functions that cause those warnings. Search the forum for that error and you'll find plenty of threads describing it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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