Batch VS AHK Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mrdigitalis
Posts: 67
Joined: 23 May 2022, 01:17

Batch VS AHK

Post by mrdigitalis » 13 Aug 2022, 15:15

Dear Form-members,

I have a question, I want to use this batch code:

test.bat

Code: Select all

RUNDLL32 PRINTUI.DLL,PrintUIEntry /e /n\\PRN-MNG01\Xerox_Secure
Result:
image.png
image.png (92.05 KiB) Viewed 1334 times
But I want to use this is AHK, but I cannot get this to work.
Can someone point me in the ricght direction?

Here is the code so far:

Code: Select all

Set_Color_ON()
{
   cmd.exe
   cd H:\Settings\Desktop
   Run, RUNDLL32.exe PRINTUI.DLL,PrintUIEntry /e /n\\PRN-MNG01\Xerox_Secure
   
   #IfWinActive ahk_class #32770
   
   Control, ChooseString, Off, ComboBox3
   SoundBeep, 1500
   msgbox Einde
   Return
   #IfWinActive
}

         
^F3::Set_Color_ON() 
Thank you for helping me!

User avatar
mikeyww
Posts: 26760
Joined: 09 Sep 2014, 18:38

Re: Batch VS AHK

Post by mikeyww » 13 Aug 2022, 15:18

To use a comma in a Run command line, escape it as `,.

Explained: Escape sequencesExample

#If is used only for hotkeys & hotstrings.

Explained: #IfWinActive

mrdigitalis
Posts: 67
Joined: 23 May 2022, 01:17

Re: Batch VS AHK

Post by mrdigitalis » 13 Aug 2022, 15:27

@mikeyww

Thank you, I escaped the comma now, but I still have this error:

Code: Select all

Set_Color_ON()
{
   cmd.exe
   cd H:\Settings\Desktop
   Run, RUNDLL32.exe PRINTUI.DLL',PrintUIEntry /e /n\\PRN-MNG01\Xerox_Secure
   
   #IfWinActive ahk_class #32770
   
   Control, ChooseString, Off, ComboBox3
   SoundBeep, 1500
   msgbox Einde
   Return
   #IfWinActive
}

         
^F3::Set_Color_ON()  
image.png
image.png (7.27 KiB) Viewed 1318 times

User avatar
mikeyww
Posts: 26760
Joined: 09 Sep 2014, 18:38

Re: Batch VS AHK

Post by mikeyww » 13 Aug 2022, 15:30

The escape character is a backtick rather than an apostrophe. You can copy and paste it from the documentation or my post.

cd is not an AutoHotkey command. SetWorkingDir

In AutoHotkey, use AutoHotkey commands. The documentation contains a list of every command and AHK function. Read about #IfWinActive there.

User avatar
Xtra
Posts: 2749
Joined: 02 Oct 2015, 12:15

Re: Batch VS AHK

Post by Xtra » 13 Aug 2022, 16:09

Try:
Run, %ComSpec% /c H: & cd "H:\Settings\Desktop" & PRINTUI.DLL`, PrintUIEntry /e /n\\PRN-MNG01\Xerox_Secure

mrdigitalis
Posts: 67
Joined: 23 May 2022, 01:17

Re: Batch VS AHK

Post by mrdigitalis » 14 Aug 2022, 05:15

@mikeyww
Now I have this code and this works now:

Code: Select all

; De functie zet de default printerinstelling Zwart/Wit om in kleur en enkelzijdig printen.
Set_Color_ON()
{
   cmd.exe
   SetWorkingDir, H:\Settings\Desktop
   Run, RUNDLL32.exe PRINTUI.DLL`,PrintUIEntry /e /n\\PRN-MNG01\Xerox_Secure
   Sleep, 5000
   If WinActive("ahk_class #32770")
   Sleep, 1000
   Control, ChooseString, 1-Sided Print, ComboBox2
   Sleep, 2000
   Control, ChooseString, Off, ComboBox3
   Sleep, 2000
   ControlClick,Button7,ahk_class #32770,&Apply
   Sleep, 2000
   ControlClick,Button5,ahk_class #32770,OK 
   Sleep, 2000
   ;Return
   WinClose
}

         
^F3::Set_Color_ON()      
;Set_Color_ON()

;---------------------------------------------------------------------------------------------------

; De functie zet de default printerinstelling kleur om in zwart/wit en dubbelzijdig printen 
Set_Color_OFF()
{
   cmd.exe
   SetWorkingDir, H:\Settings\Desktop
   Run, RUNDLL32.exe PRINTUI.DLL`,PrintUIEntry /e /n\\PRN-MNG01\Xerox_Secure
   Sleep, 5000
   If WinActive("ahk_class #32770")
   Sleep, 2000
   Control, ChooseString, 2-Sided Print, ComboBox2
   Sleep, 2000
   Control, ChooseString, On, ComboBox3
   Sleep, 2000
   ControlClick,Button7,ahk_class #32770,&Apply
   Sleep, 2000
   ControlClick,Button5,ahk_class #32770,OK 
   Sleep, 2000
   ;Return
   WinClose
}

^F4::Set_Color_OFF()      
;Set_Color_OFF()
And thanks @Xtra

User avatar
mikeyww
Posts: 26760
Joined: 09 Sep 2014, 18:38

Re: Batch VS AHK  Topic is solved

Post by mikeyww » 14 Aug 2022, 05:26

Good. You can delete lines 4 and 31.

A demonstration is below.

Code: Select all

cmd := {exe: 5}
cmd.exe
MsgBox % cmd.exe
Explained: Associative arrays

The following sort of thing might work.

Code: Select all

^F3::setColor(True)
^F4::setColor(False)

setColor(on := True) {
 SetWorkingDir, H:\Settings\Desktop
 Run, RUNDLL32.exe PRINTUI.DLL`,PrintUIEntry /e /n\\PRN-MNG01\Xerox_Secure
 WinWait, ahk_class #32770,, 5
 If ErrorLevel {
  MsgBox, 48, Error, An error occurred while waiting for the window.
  Return
 }
 If on {
  Control, ChooseString, 1-Sided Print, ComboBox2
  Control, ChooseString, Off          , ComboBox3
 } Else {
  Control, ChooseString, 2-Sided Print, ComboBox2
  Control, ChooseString, On           , ComboBox3
 }
 ControlClick, Button7,, &Apply
 ControlClick, Button5,, OK
 Sleep, 1500
 WinClose
}

mrdigitalis
Posts: 67
Joined: 23 May 2022, 01:17

Re: Batch VS AHK

Post by mrdigitalis » 14 Aug 2022, 13:34

@mikeyww thats really cool!

Thank you very much!

Post Reply

Return to “Ask for Help (v1)”