Jump to content

Recommended Posts

Posted

I've got Windows 11 configured to open Snipping Tool when the PrintScreen button is pressed, but sometimes it quits working. I have no idea why, it just does nothing when I hit the key.

Once or twice when I checked Task Manager there was a SnippingTool.exe running, but with no interface showing in Windows. Which might explain why the new Snipping Tool Overlay didn't launch. Sometimes when PrintScreen fails, though, SnippingTool.exe isn't running in processes. So it's like a 2-for-1 special glitch.

So I created this script.

Global $gLogFile = @ScriptDir & "\LOG.txt"

AdlibRegister(_Handle_PrintScreenBug, 10)

While 1
    Sleep(500)
Wend

Func _Handle_PrintScreenBug()
    $lFuncName = "_Handle_PrintScreenBug"
    $lTarget_SnippingTool_Overlay_Title = "Snipping Tool Overlay"
    $lTarget_Process = "SnippingTool.exe"

    If _IsPressed($VK_SNAPSHOT) Then
        Sleep(1000)
        If Not WinExists($lTarget_SnippingTool_Overlay_Title) Then ;Then Print Screen didn't work.
            _Log($lFuncName, "PrintScreen key failed to launch Snipping Tool Overlay.")
            If ProcessExists($lTarget_Process) Then
                _Log($lFuncName, "SnippingTool.exe stuck running hidden.")
                While ProcessExists($lTarget_Process)
                    ProcessClose($lTarget_Process)
                WEnd
                _Log($lFuncName, "Exited SnippingTool.exe Process.")
                Send("#+S")
                _Log($lFuncName, "Manually input Snipping Tool hotkey.")
            Else
                _Log($lFuncName, "SnippingTool.exe process does not exist.")
                ; PrintScreen key did not work, but the process wasn't hung.
                Send("#+S")
                _Log($lFuncName, "Manually input Snipping Tool hotkey.")
            EndIf
        EndIf
    EndIf
EndFunc   ;==>_Handle_PrintScreenBug

Func _Log($pFunctionName, $pData)
    Local $lOutput = "[" & _Now() & "]" & $pFunctionName & ": " & $pData
    If @Compiled Then 
        FileWriteLine($gLogFile, $lOutput)
    Else
        ConsoleWrite($lOutput & @CRLF)
    EndIf
EndFunc   ;==>_Log

I use AdLibRegister, because this is only part of a larger file that I use called "MiscSystemFixes" and the script does a few additional things. And rather than cram all these fixes into a single loop, I wanted to compartmentalize with AdlibRegister. As for why I don't just hit the CTRL+SHIFT+S instead of the PrintScreen key, I've just done that for years and it's easier than having to contort my hand to press a 3-character hotkey and remember to do that instead of hitting PrintScreen.

My question: Does that look fairly straightforward and efficient?

 

 

SIGNATURE_0X800007D NOT FOUND

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
×
×
  • Create New...