Question

I'm new to AutoHotKey, so this could be something bone-headed on my part. I put this together yesterday, and it worked fine all day. Today it is failing to fully execute at random times.

What I'm doing is forcing Chrome to use the System Print Dialog, and then printing only the first page.

!NumpadDiv::
{
    Send ^P              ; CTRL+SHIFT+p forces System Print Dialog
    WinWait, Print, , 2  ; Wait for Print Dialog to appear
    if ErrorLevel
    {
        MsgBox, WinWait timed out.
        return
    }
    else
    {
        IfWinActive, Print    ; Added to ensure Print window was active
        {
        SetKeyDelay, 300    ; Upped key delay. Thought this may help. It hasn't
            Send {TAB 4}        ; Tabs over to Page Range
            Send 1              ; Print only first page
            Send {Enter}
        }
    }
    return
}

Today the script started failing at random times. Either it does not tab over to the page range, and will print all pages, or it will tab to it, enter 1 then not print. In both cases, it triggers my PC's error sound. Any help would be appreciated, I'm very confused since this was working without issue all day yesterday.

Was it helpful?

Solution

I want to do similar thing in Lotus Notes too. I've revisited clangford1174's code based on MCL's advice as below. It works on my Win7 machine.

!NumpadDiv::
{
    Send ^P              ; CTRL+SHIFT+p forces System Print Dialog
    WinWait, Print, , 2  ; Wait for Print Dialog to appear
    if ErrorLevel
    {
        MsgBox, WinWait timed out.
        return
    }
    else
    {   
        ControlSetText, Edit4, 1
        Send {Enter}        
    }
    return
}

BTW, This thread on selecting printer with AHK is relevant too. How to select printer and print with AutoHotKey

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top