How to print to a specific printer with single key?

Get help with using AutoHotkey and its commands and hotkeys
MortenZdk
Posts: 9
Joined: 25 Aug 2018, 06:02

How to print to a specific printer with single key?

25 Aug 2018, 06:22

Having multiple printers, it would save some keystrokes if I can define a key to print to a specific printer.

Is that possible ?

Thanks and best regards,
Morten
User avatar
Scr1pter
Posts: 1069
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: How to print to a specific printer with single key?

25 Aug 2018, 09:35

Hi Morten,

I am very sure this is possibile.
As far as I remember, by default you can press Ctrl+P to activate the print dialogue.
(I don't have a printer on my PC, so I can't test it.)

The question is, what do you have to do manually to select a printer?
If you just have to use the arrow keys and press Enter, it will be pretty easy.

It means your script will look something like:

Code: Select all

F1:
Select_Printer(0) ; First printer in list
return

F2:
Select_Printer(1) ; Second printer in list
return

F3:
Select_Printer(2) ; Third printer in list
return

F4:
Select_Printer(3) ; Fourth printer in list
return

Select_Printer(p)
{
  Send ^p ; Open print dialogue
  Sleep, 500 ; Puffer time until the dialogue gets opened
  Send {PgUp} ; Select first printer in list
  Sleep, 5
  Send {Down %p%} ; Select target printer
  Sleep, 5
  Send {Enter} ; Press ok
}
By using the keys F1 till F4 (you can change them of course), you activate the function
and send a value which gets interpreted as
Press Arrow key down X times.

But before you try the script, you have to check it manually.
Press Ctrl+P and look if the arrow keys change the printer.

Edit
Or do you actually want to press only 1 key?
In that case you could use a Gui where you can select the target printer.

Regards
Please use code tags when posting code!
Keyboard: Logitech G15 FE - Mice: Logitech G9 FE, G502 FE, G602 - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.29.00
MortenZdk
Posts: 9
Joined: 25 Aug 2018, 06:02

Re: How to print to a specific printer with single key?

11 Sep 2018, 09:43

Hi Scr1pter,

Thanks for your comment.

I ended up making a fuction that could customice per program, like this:

Code: Select all

; Get program of active window
MyWinGetPrg()
{
  WinGetTitle, title, A
  part_array := StrSplit(title, "-")
  part_last := Trim(part_array[part_array.MaxIndex()])
  Return part_last
}

; Print function for print directly to named printer through dialog box.
; 
; Note that if the select key for the printer name field in the dialog box may
; vary, so this can be given using SelKey argument.
PrintNamed(name)
{
  ; Determine control values: sel_key, wait_box
  ptr_key := "^p"    ; Default
  sel_key := "!n"    ; --||--
  wait_box := 200    ; --||--
  wait_enter := 100  ; --||--
  prg := MyWinGetPrg()
  if (prg = "Mozilla Thunderbird") {
    wait_box := 1000
    wait_enter := 300
  } else if (prg = "Mozilla Firefox") {
    wait_enter := 200
  } else if (prg = "Foxit PhantomPDF") {
    ptr_key := "{Alt Down}fp{Alt Up}"
    wait_enter := 800
  }
  ; Print based on settings
  Send %ptr_key%    ; Send Control P to print
  Sleep %wait_box%  ; Wait for print dialoguebox
  Send %sel_key%    ; Select printer name field
  Send %name%
  Sleep %wait_enter%
  Send {Enter}
}

; Shortcuts for printers
^!P::PrintNamed("Bullzip PDF")
^!+P::PrintNamed("Samsung ML")

Return to “Ask For Help”

Who is online

Users browsing this forum: asad41163, Google [Bot], Timmy347 and 214 guests