Jump to content

Stack Overflow With Hotkeyset?


Recommended Posts

At my workplace we are required to lock our computers anytime we leave our desks. If anyone forgets to "WinKey+L", anyone else there quickly gets on the computer and messes with the wallpaper, themes, start menu, desktop, etc... :) Our screensavers are unfortunately locked at 30 minutes by the administrator, so I can't set it to 2 minutes to save myself...

To remedy this, I've written up a little script that checks for mouse activity or suspicious processes, and locks the computer within 5 seconds unless a certain key sequence is pressed. The problem I'm having (or at least what I think the problem is) is that using HotKeySet to jump out of a function, and then go back into another function is causing a stack overflow (with enough time) because the function never returns properly. I've tried a few approaches, but I can't think of any way to clear the stack when using HotKeySet.

Any ideas?

opt("TrayIconHide",1)
HotKeySet("^+!zx","isOk")

While 1
    checker()
WEnd

Func checker()
    While 1
        if WinExists("Taskbar and Start Menu Properties") = 1 Then promptID()
        if WinExists("Display Properties") = 1 Then promptID()
        if WinExists("Control Panel") = 1 Then promptID()
        if WinExists("Windows Task Manager") = 1 Then promptID()
            
        $t = 0
        $pos = MouseGetPos()
        Sleep(1000)
        $newpos = MouseGetPos()
        While $pos[0] = $newpos[0]
            $t = $t + 1
            If $t > 120 Then promptID()
            Sleep(1000)
            $newpos = MouseGetPos()
        WEnd
    WEnd
EndFunc

Func promptID()
    ToolTip("Please identify yourself... 5")
    Sleep(1000)
    ToolTip("Please identify yourself... 4")
    Sleep(1000)
    ToolTip("Please identify yourself... 3")
    Sleep(1000)
    ToolTip("Please identify yourself... 2")
    Sleep(1000)
    ToolTip("Please identify yourself... 1")
    Sleep(1000)
    ToolTip("GET OFF MY COMPUTER!")
    Sleep(1000)
    Send("#l")
    checker()
EndFunc

Func isOk()
    ToolTip("Thank you...")
    Sleep(1000)
    ToolTip("")
    Sleep(60000)
    checker()
EndFunc
Link to comment
Share on other sites

  • Developers

The problem I'm having (or at least what I think the problem is) is that using HotKeySet to jump out of a function, and then go back into another function is causing a stack overflow (with enough time) because the function never returns properly. I've tried a few approaches, but I can't think of any way to clear the stack when using HotKeySet.

Any ideas?

None of your Functions end properly... they all start a new Func.

Checker() calls PromptId() and PromptId() call Checker()...

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

None of your Functions end properly...

I noticed that :) and have been working on a new version that returns functions properly. I was able to get checker() and promptID() to return properly, but since I can't control where HotKeySet function isOK() is called from, I have to exit it by calling another part of the code. I was hoping for a "goto" sort of command.. something that doesn't write its departure location onto the stack.

Edited by Jynxst
Link to comment
Share on other sites

Untested.. but how about:

opt("TrayIconHide",1)
HotKeySet("^+!zx","isOk")

    While 1
        if WinExists("Taskbar and Start Menu Properties") = 1 Then promptID()
        if WinExists("Display Properties") = 1 Then promptID()
        if WinExists("Control Panel") = 1 Then promptID()
        if WinExists("Windows Task Manager") = 1 Then promptID()
            
        $t = 0
        $pos = MouseGetPos()
        Sleep(1000)
        $newpos = MouseGetPos()
        While $pos[0] = $newpos[0]
            $t = $t + 1
            If $t > 120 Then promptID()
            Sleep(1000)
            $newpos = MouseGetPos()
        WEnd
    WEnd


Func promptID()
    ToolTip("Please identify yourself... 5")
    Sleep(1000)
    ToolTip("Please identify yourself... 4")
    Sleep(1000)
    ToolTip("Please identify yourself... 3")
    Sleep(1000)
    ToolTip("Please identify yourself... 2")
    Sleep(1000)
    ToolTip("Please identify yourself... 1")
    Sleep(1000)
    ToolTip("GET OFF MY COMPUTER!")
    Sleep(1000)
    Send("#l")

EndFunc

Func isOk()
    ToolTip("Thank you...")
    Sleep(1000)
    ToolTip("")
    Sleep(60000)

EndFunc

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Untested.. but how about:

This is exactly what my 'new version' is... guess I should have posted it instead of my original script. :">

The issue with it is that if promptID() is called and the countdown begins, and the user enters in the proper keys, calling isOk() through HotKeySet, it doesn't end the countdown when isOk() returns to promptID().

Maybe I should ask a different question - is there a way to clear the stack in AutoIt? This would solve my problem without having to rewrite my very bad function1 to function2 to function1 code. :)

Link to comment
Share on other sites

;opt("TrayIconHide", 1); commented out for testing
HotKeySet("^+!zx", "isOk")
$timer = TimerInit()

While 1
    $dif = TimerDiff($timer); initiate a timer
    If $dif > 60000 Then; if its been more than 60 sec since timer was reset
        If WinExists("Taskbar and Start Menu Properties") = 1 Then promptID()
        If WinExists("Display Properties") = 1 Then promptID()
        If WinExists("Control Panel") = 1 Then promptID()
        If WinExists("Windows Task Manager") = 1 Then promptID()
        
        $t = 0
        $pos = MouseGetPos()
        Sleep(1000)
        $newpos = MouseGetPos()
        While $pos[0] = $newpos[0]
            $t = $t + 1
            If $t > 120 Then promptID()
            Sleep(1000)
            $newpos = MouseGetPos()
        WEnd
    EndIf
    Sleep(500); so you dont eat up your processor
WEnd


Func promptID()
    ToolTip("Please identify yourself... 5")
    Sleep(1000)
    ToolTip("Please identify yourself... 4")
    Sleep(1000)
    ToolTip("Please identify yourself... 3")
    Sleep(1000)
    ToolTip("Please identify yourself... 2")
    Sleep(1000)
    ToolTip("Please identify yourself... 1")
    Sleep(1000)
    ToolTip("GET OFF MY COMPUTER!")
    Sleep(1000)
    Send("#l")
    
EndFunc ;==>promptID

Func isOk()
    ToolTip("Thank you...")
    Sleep(1000)
    ToolTip("")
    $timer = TimerInit(); reset timer after you do your hotkey thing
EndFunc ;==>isOk

also I don't tlhink the mousemove stuff is doing what you want it to do.

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Oops, missed what you were shooting for there. This should work though. (I dont know about clearing the stack)

;opt("TrayIconHide", 1); commented out for testing
HotKeySet("^+!zx", "isOk")
Global $clear
$timer = TimerInit()

While 1
    $dif = TimerDiff($timer); check the timer
    If $dif > 60000 Then; if its been more than 60 sec since timer was reset
        If WinExists("Taskbar and Start Menu Properties") = 1 Then promptID()
        If WinExists("Display Properties") = 1 Then promptID()
        If WinExists("Control Panel") = 1 Then promptID()
        If WinExists("Windows Task Manager") = 1 Then promptID()
        
        $t = 0
        $pos = MouseGetPos()
        Sleep(1000)
        $newpos = MouseGetPos()
        While $pos[0] = $newpos[0]
            $t = $t + 1
            If $t > 120 Then promptID()
            Sleep(1000)
            $newpos = MouseGetPos()
        WEnd
    EndIf
    Sleep(500); so you dont eat up your processor
WEnd


Func promptID()
    $clear = 0
    If $clear = 0 Then warn(5)
    If $clear = 0 Then warn(4)
    If $clear = 0 Then warn(3)
    If $clear = 0 Then warn(2)
    If $clear = 0 Then warn(1)
    If $clear = 0 Then attack()
EndFunc  ;==>promptID

Func isOk()
    ToolTip("Thank you...")
    Sleep(1000)
    ToolTip("")
    $timer = TimerInit(); reset timer after you do your hotkey thing
    $clear = 1; Clear the warning flag
EndFunc  ;==>isOk

Func warn($x)
    ToolTip("Please identify yourself... " & $x)
    Sleep(1000)
EndFunc  ;==>warn

Func attack()
    ToolTip("GET OFF MY COMPUTER!")
    Sleep(1000)
    Send("#l")
EndFunc  ;==>attack

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Thanks for the replies Spook, I was able to fix the issue by reworking the script using your code as a reference. I don't necessarily like using a global variable to act as an ok/notok flag, but it sure beats overflowing the stack!

Now it's time to leave my computer unlocked and catch some mice with my trap! :)

Jynxst

Link to comment
Share on other sites

I kind of like having a sound warning that first turns up the volume all the way, then blast out something along the lines of a tweedy bird voice "HELP!, HELP! SOMEONE IS MOLESTING ME! HELP!" or "HEY EVERYBODY, I"M MESSING WITH %your name" COMPUTER. HE WILL NEVER KNOW WHO DID IT! COME QUICK SO YOU CAN SEE WHAT I DID!" The possibilities are endless.....

:mellow:

:)

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...