How to Get and/or Set "Selected" Printer (Not Default Printer) in Print Window as shown in image
and to you in Advance
Get or Set selected printer in Print Window Topic is solved
-
- Posts: 112
- Joined: 06 Jun 2016, 21:32
Get or Set selected printer in Print Window
- Attachments
-
- PrintIssue.png (23.52 KiB) Viewed 1466 times
Re: Get or Set selected printer in Print Window
This is my cheater's method. If you search the forum for "ExtListView", you will find a library that provides more features. I have not tried it.
Code: Select all
printerNumber = 4
F3::
Send ^p
WinWaitActive, Print ahk_class #32770,, 3
If ErrorLevel
MsgBox, 48, Error, An error occurred while waiting for the print dialog.
Else Send % "{Home}{Down " printerNumber - 1 "}"
Return
-
- Posts: 112
- Joined: 06 Jun 2016, 21:32
Re: Get or Set selected printer in Print Window
hey mikey,,mikeyww wrote: ↑05 Dec 2021, 06:45This is my cheater's method. If you search the forum for "ExtListView", you will find a library that provides more features. I have not tried it.
Code: Select all
printerNumber = 4 F3:: Send ^p WinWaitActive, Print ahk_class #32770,, 3 If ErrorLevel MsgBox, 48, Error, An error occurred while waiting for the print dialog. Else Send % "{Home}{Down " printerNumber - 1 "}" Return
thanks for the reply and taking interest in the topic
The idea is good, but its not reliable,,
sometimes it will select another printer
(mostly, at the time of system hanging)
Re: Get or Set selected printer in Print Window
OK. You could try the ExtListView. You might have better luck than I did.
Re: Get or Set selected printer in Print Window Topic is solved
Code: Select all
$q::SelectPrinter("Bullzip PDF Printer") ; <<--- put the printer name you want to print with here
SelectPrinter(Printer)
{
static wintitle := "Print ahk_class #32770"
WinWait, % wintitle,, 10
if (ErrorLevel)
return false
ControlGet, LV, List,, SysListView321, % wintitle
Loop, Parse, LV, `n, `r
{
currPrinter := SubStr(A_LoopField, 1, InStr(A_LoopField, A_Tab) - 1)
if (currPrinter = Printer) {
ControlGet, HLV, Hwnd,, SysListView321, % wintitle
return LV_DoubleClickRow(HLV, A_Index)
}
}
return false
}
LV_DoubleClickRow(HLV, Row) ; You can thank Justme for this function
{ ; HLV : ListView's HWND, Row : 1-based row number
HPROC := 0
MyPID := DllCall("GetCurrentProcessId", "UInt")
WinGet, LVPID, PID, ahk_id %HLV%
If !(LVPID)
Return False
VarSetCapacity(RECT, 16, 0)
If (LVPID <> MyPID) {
If !(HPROC := DllCall("OpenProcess", "UInt", 0x0438, "Int", False, "UInt", LVPID, "Ptr"))
Return False
If !(Addr := DllCall("VirtualAllocEx", "Ptr", HPROC, "Ptr", 0, "UPtr", 16, "UInt", 0x1000, "UInt", 4, "UPtr"))
Return (DllCall("CloseHandle", "Ptr", HPROC) & 0) ; False
}
Else
Addr := &RECT
SendMessage, 0x1013, % (Row - 1), 1, , ahk_id %HLV% ; LVM_ENSUREVISIBLE
SendMessage, 0x100E, % (Row - 1), %Addr%, , ahk_id %HLV% ; LVM_GETITEMRECT
If (HPROC) {
DllCall("ReadProcessMemory", "Ptr", HPROC, "Ptr", Addr, "Ptr", &RECT, "UPtr", 16, "Ptr", 0)
DllCall("VirtualFreeEx", "Ptr", HPROC, "Ptr", Addr, "UPtr", 0, "UInt", 0x8000)
DllCall("CloseHandle", "Ptr", HPROC)
}
POINT := NumGet(RECT, 0, "Short") | (NumGet(RECT, 4, "Short") << 16)
PostMessage, 0x0201, 0, POINT, , ahk_id %HLV% ; WM_LBUTTONDOWN
PostMessage, 0x0202, 0, POINT, , ahk_id %HLV% ; WM_LBUTTONUP
PostMessage, 0x0203, 0, POINT, , ahk_id %HLV% ; WM_LBUTTONDBLCLK
PostMessage, 0x0202, 0, POINT, , ahk_id %HLV% ; WM_LBUTTONUP
Return True
}
Re: Get or Set selected printer in Print Window
toggle between 2 printers ( make default )
Code: Select all
printerA:="Pantum M6600NW Series"
;printerB:="Samsung SCX-4200 Series (USB001)"
printerB:="Samsung Network PC Fax"
return
!h::
T:=!T
if (T=1)
{
msgbox,%printera%
runwait,%comspec% /c rundll32 printui.dll`,PrintUIEntry /y /n "%printerA%",,hide ;- make printer-A default
}
else
{
msgbox,%printerb%
runwait,%comspec% /c rundll32 printui.dll`,PrintUIEntry /y /n "%printerB%",,hide ;- make printer-B default
}
;run,shell:PrintersFolder
run,control printers
return
;============================================================================================
-
- Posts: 112
- Joined: 06 Jun 2016, 21:32
Re: Get or Set selected printer in Print Window
Xtra wrote: ↑05 Dec 2021, 22:39HTHCode: Select all
$q::SelectPrinter("Bullzip PDF Printer") ; <<--- put the printer name you want to print with here SelectPrinter(Printer) { static wintitle := "Print ahk_class #32770" WinWait, % wintitle,, 10 if (ErrorLevel) return false ControlGet, LV, List,, SysListView321, % wintitle Loop, Parse, LV, `n, `r { currPrinter := SubStr(A_LoopField, 1, InStr(A_LoopField, A_Tab) - 1) if (currPrinter = Printer) { ControlGet, HLV, Hwnd,, SysListView321, % wintitle return LV_DoubleClickRow(HLV, A_Index) } } return false } LV_DoubleClickRow(HLV, Row) ; You can thank Justme for this function { ; HLV : ListView's HWND, Row : 1-based row number HPROC := 0 MyPID := DllCall("GetCurrentProcessId", "UInt") WinGet, LVPID, PID, ahk_id %HLV% If !(LVPID) Return False VarSetCapacity(RECT, 16, 0) If (LVPID <> MyPID) { If !(HPROC := DllCall("OpenProcess", "UInt", 0x0438, "Int", False, "UInt", LVPID, "Ptr")) Return False If !(Addr := DllCall("VirtualAllocEx", "Ptr", HPROC, "Ptr", 0, "UPtr", 16, "UInt", 0x1000, "UInt", 4, "UPtr")) Return (DllCall("CloseHandle", "Ptr", HPROC) & 0) ; False } Else Addr := &RECT SendMessage, 0x1013, % (Row - 1), 1, , ahk_id %HLV% ; LVM_ENSUREVISIBLE SendMessage, 0x100E, % (Row - 1), %Addr%, , ahk_id %HLV% ; LVM_GETITEMRECT If (HPROC) { DllCall("ReadProcessMemory", "Ptr", HPROC, "Ptr", Addr, "Ptr", &RECT, "UPtr", 16, "Ptr", 0) DllCall("VirtualFreeEx", "Ptr", HPROC, "Ptr", Addr, "UPtr", 0, "UInt", 0x8000) DllCall("CloseHandle", "Ptr", HPROC) } POINT := NumGet(RECT, 0, "Short") | (NumGet(RECT, 4, "Short") << 16) PostMessage, 0x0201, 0, POINT, , ahk_id %HLV% ; WM_LBUTTONDOWN PostMessage, 0x0202, 0, POINT, , ahk_id %HLV% ; WM_LBUTTONUP PostMessage, 0x0203, 0, POINT, , ahk_id %HLV% ; WM_LBUTTONDBLCLK PostMessage, 0x0202, 0, POINT, , ahk_id %HLV% ; WM_LBUTTONUP Return True }
OMG!! OMG!! OMG!!
its, its... working!!
I would like to know 2 things
1) How to select only [No doubble click, No print, only select]
2) Is Justme = X
in comment line of function ---> "; You can thank Justme for this function"
-
- Posts: 112
- Joined: 06 Jun 2016, 21:32
Re: Get or Set selected printer in Print Window
Hi garry,,garry wrote: ↑06 Dec 2021, 13:47toggle between 2 printers ( make default )Code: Select all
printerA:="Pantum M6600NW Series" ;printerB:="Samsung SCX-4200 Series (USB001)" printerB:="Samsung Network PC Fax" return !h:: T:=!T if (T=1) { msgbox,%printera% runwait,%comspec% /c rundll32 printui.dll`,PrintUIEntry /y /n "%printerA%",,hide ;- make printer-A default } else { msgbox,%printerb% runwait,%comspec% /c rundll32 printui.dll`,PrintUIEntry /y /n "%printerB%",,hide ;- make printer-B default } ;run,shell:PrintersFolder run,control printers return ;============================================================================================
Thank you too for showing interest in this topic
The problem is "pritner selection is getting changed after once print button clicked for next print, even another printer is already defaulted"
and,
my situation is the print pop-up is coming by a website online,,.
Re: Get or Set selected printer in Print Window
Its using double click so you don't have to select and then click the print button clearly easier? I don't see a point in selecting a printer and doing nothing else.MonuKashyap wrote: ↑06 Dec 2021, 21:28I would like to know 2 things
1) How to select only [No doubble click, No print, only select]
2) Is Justme = X
in comment line of function ---> "; You can thank Justme for this function"
@just me is the one you can thank.
Try commenting out these lines:
Code: Select all
PostMessage, 0x0203, 0, POINT, , ahk_id %HLV% ; WM_LBUTTONDBLCLK
PostMessage, 0x0202, 0, POINT, , ahk_id %HLV% ; WM_LBUTTONUP
-
- Posts: 112
- Joined: 06 Jun 2016, 21:32
Re: Get or Set selected printer in Print Window
actually the situation is:Xtra wrote: ↑06 Dec 2021, 22:11Its using double click so you don't have to select and then click the print button clearly easier? I don't see a point in selecting a printer and doing nothing else.MonuKashyap wrote: ↑06 Dec 2021, 21:28I would like to know 2 things
1) How to select only [No doubble click, No print, only select]
2) Is Justme = X
in comment line of function ---> "; You can thank Justme for this function"
@just me is the one you can thank.
Try commenting out these lines:Code: Select all
PostMessage, 0x0203, 0, POINT, , ahk_id %HLV% ; WM_LBUTTONDBLCLK PostMessage, 0x0202, 0, POINT, , ahk_id %HLV% ; WM_LBUTTONUP
There are 2 printers
1) To pdf
2) To paper
and here "To pdf" is compulsary, and "To paper" is optional
so if we want to print to paper so we need only to press enter
and, your solution is working superb,,
Thanks a lot