Jump to content

Event based user activity detection


Recommended Posts

I'm in a process of optimizing my script to converts message boxes into notification-like popup.

My last challenge is to bring down CPU usage to 0 while detecting click/key press in external application to hide my popup without interrupting.

Currently I'm using this in a loop:

For $i = 0 To 255
                If (_IsPressed(Hex($i), $hUser32_Dll)) Then
                    closePopup()
                    ExitLoop
                EndIf
            Next

It works fine, however it uses 3% CPU

 

I know I could use _WinAPI_UnhookWindowsHookEx for $WH_KEYBOARD and $WH_MOUSE events, which I've tested, and it works wonderfully.

But perhaps there is a better method available?

 

Thank you.

Edited by VAN0
Link to comment
Share on other sites

Is the goal to suppress your popup if the user does any activity, or specific key presses or mouse clicks?

One idea that comes to mind is just check idle time. 

_WinAPI_GetIdleTime()

 

Edited by spudw2k
Link to comment
Share on other sites

My idea was to show a popup, and hide it after 10 sec, however if user continue working with that program, like pressed any key, or clicked, then hide the popup so it doesn't interfere.

_WinAPI_GetIdleTime() wouldn't work, because it's triggered by mouse move, also, I'm trying to avoid using the loop, as it seems to be the most inefficient. So far, I'm achieving 0% CPU usage by registering $WH_KEYBOARD and $WH_MOUSE event listener while popup is opened and deregistering it when it's closed.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...