I got an Auto-Hotkey script

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Recommended for catching common errors.
SendMode Event  ; Input worked hardly, "Event" is better.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 1 ; 1: A window's title must start with the specified WinTitle to be a match.

#IfWinActive Zooming Viewer
~RButton & WheelDown::
    Send {Ctrl Down} {WheelUp} {Ctrl Up}
    return
~RButton & WheelUp::
    Send {Ctrl Down} {WheelDown} {Ctrl Up}
    return

Ref.: How do I make Auto Hotkey convert "RButton down, Mousewheel action, RButton up" into "MButton down, Mouse moving up & down, MButton up""

How do I make this script surviving desktop lock on Win-7? After freeing the locked computer, the viewer behaves as without AHK-script. Clicking on the script menu in notification area, chosing "Reload This Script" makes it work again – but forced to do so seems a little bit annoying.

Try

#Warn  ; Recommended for catching common errors.
SendMode Event  ; Input worked hardly, "Event" is better.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 1 ; 1: A window's title must start with the specified WinTitle to be a match.

MsgBox, Reloading

OnMessage(0x2b1,"WM_WTSSESSION_CHANGE")
Gui,+LastFound
hwnd:=WinExist()
DllCall("Wtsapi32.dll\WTSRegisterSessionNotification","UInt",hwnd,"UInt",0)
    Return


#IfWinActive Zooming Viewer

    ~RButton & WheelDown::
        Send {Ctrl Down} {WheelUp} {Ctrl Up}
        return
    ~RButton & WheelUp::
        Send {Ctrl Down} {WheelDown} {Ctrl Up}
        return

#IfWinActive

WM_WTSSESSION_CHANGE(wParam,lParam){
    static _0x1:="WTS_CONSOLE_CONNECT" ;A session was connected to the console terminal.
    ; ,_0x2:="WTS_CONSOLE_DISCONNECT" ;A session was disconnected from the console terminal.
    ; ,_0x3:="WTS_REMOTE_CONNECT" ;A session was connected to the remote terminal.
    ; ,_0x4:="WTS_REMOTE_DISCONNECT" ;A session was disconnected from the remote terminal.
    ,_0x5:="WTS_SESSION_LOGON" ;A user has logged on to the session.
    ; ,_0x6:="WTS_SESSION_LOGOFF" ;A user has logged off the session.
    ; ,_0x7:="WTS_SESSION_LOCK" ;A session has been locked.
    ,_0x8:="WTS_SESSION_UNLOCK" ;A session has been unlocked.
    ; ,_0x9:="WTS_SESSION_REMOTE_CONTROL" ;A session has changed its remote controlled status. To determine the status, call GetSystemMetrics and check the SM_REMOTECONTROL metric.
    Reload
}

https://autohotkey.com/board/topic/42717-how-to-execute-a-script-when-a-computer-is-locked/page-2#entry266488

  • According to the source, it is for "detect when workstation gets locked". I don't want to detect it, I just want to let the script survive locking (or rather unlocking?). If the script doesn't run anymore, how should detecting locking help? – Peter Aug 30 at 7:46
  • On my system it works. I get the message "Reloading" after lockIng ( Win+L) and un-lockIng (signing in) the workstation. – user3419297 Aug 30 at 7:57
  • Or did your mean to start another script that's supervising the other script and reloads it if necessary? – Peter Aug 30 at 8:00
  • No, while the script is running I press Win+L and after signing in I get the message "Reloading" from the same script. – user3419297 Aug 30 at 8:13
  • If it works, I think there is another underlying problem, that becomes solved by restarting. If this script can detect unlocking, it should also do its real task – the scrollwheel translation. Or am I wrong? – Peter Aug 30 at 8:15

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.