Help with Variable Subtraction

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Posts: 3
Joined: 01 Sep 2016, 10:29

Help with Variable Subtraction

10 Jun 2019, 20:07

Okay, so...

Below is a snippet of code from my "Everyday use" script & is intended to be run with Paint.NET (image editing software) in focus.
I'm making custom .gif emoji's for a Discord server I own & it's a very tedious process, so I look for any "fasterizing" shortcuts I can!

The goal is to save the selected (visible) layer, name it "f<number>" change the File Type to .png, confirm the save location, confirm the save, confirm flattening all layers, then Undo the flatten command so I can do the same for the next layer (because part of the process in making each layer it's own independent .png file).

That said, once on the next layer, I'd like to be able to just tap the hotkey again & have the file name be "f<previous number> -1".

num1 := 3--

F8:: ;Save .pdn As .png File.
If WinActive ("ahk_exe PaintDotNet.exe")
Send ^+s ;"Save As"
Sleep 250
Send f ;Sends "f" Leading File Name.
Sleep 250
Send %num1% ;Sends Starting Variable, Then Subtracts 1 & Makes It The New Variable.
Sleep 250
Send {TAB} ;Shifts Focus To File Type Selection Box.
Sleep 250
Send p ;Chooses .png File Format.
Sleep 250
Send {ENTER} ;Confirms Save Name & Location.
Sleep 250
Send {ENTER} ;Confirms Save.
Sleep 250
Send {ENTER} ;Confirms "Flatten".
Sleep 1000
Send ^z ;Reverts "Flatten".
Else If WinNotActive ("ahk_exe PaintDotNet.exe")
Send {vk77sc042} ;Send F8.

I'm not a coder by trade, I only dabble occasionally & I've been racking my head against this code & the AHK "Variables & Expressions" documentation for the better part of 4h & it's just not clear enough for me. If anyone needs clarification on my intent, please let me know.

Thanks in advance for all constructive feedback! :mrgreen:
User avatar
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Help with Variable Subtraction

10 Jun 2019, 21:57

Ways to do subtraction:

Code: Select all

var := 10

var := var - 3
var -= 3

MsgBox, % var ;2
Possibly for your program, if you can copy image data to the clipboard, you could: clear the clipboard, send Ctrl+C or equivalent, use ClipWait (to wait until the clipboard is not empty), and use the Gdip library to create a png from the clipboard data.

It's possible that your script may be made faster by using WinWaitActive, instead of Sleep.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Posts: 344
Joined: 24 Aug 2015, 12:56
Google: [email protected]
GitHub: YoucefHam
Location: Algeria

Re: Help with Variable Subtraction

10 Jun 2019, 22:22

try this

Code: Select all

SetKeyDelay, 60, 120

num1 := 4
#If WinActive("ahk_exe PaintDotNet.exe")

F8::		;Save .pdn As .png File.
MouseGetPos, x, y
MouseMove, 0, 0
WinGetTitle, WinT, A
ControlSend,, !fa, % WinT   ;"Save As"

WinWaitActive, Save As
Sleep, 800
ControlFocus, Edit1, ahk_exe PaintDotNet.exe
ControlSetText, Edit1, f%num1%, ahk_exe PaintDotNet.exe ;Sends Starting Variable, Then Subtracts 1 & Makes It The New Variable.

Sleep, 250
ControlFocus, ComboBox2, ahk_exe PaintDotNet.exe
Control, ChooseString, PNG (*.png) , ComboBox2, ahk_exe PaintDotNet.exe ;Selection Box. Chooses .png File Format.
Sleep, 250
ControlFocus, Button2, ahk_exe PaintDotNet.exe
ControlSend, Button2, {Space}, ahk_exe PaintDotNet.exe ;Confirms Save Name & Location.

WinWaitActive, Confirm Save As,, 2
if !ErrorLevel
	Sleep, 350
	ControlFocus, Button1, ahk_exe PaintDotNet.exe
	ControlSend, Button1, {Space}, ahk_exe PaintDotNet.exe ;Confirms Save As Name & Location.

WinWaitActive, Save Configuration
Sleep, 350
ControlFocus, Button1, ahk_exe PaintDotNet.exe
ControlClick,, ahk_exe PaintDotNet.exe ;Confirms "Flatten".

WinWaitActive, Save
Sleep, 450
ControlFocus,, ahk_exe PaintDotNet.exe
ControlClick,, ahk_exe PaintDotNet.exe ;Confirms Save

Sleep, 450
WinGetTitle, WinT, A
WinWaitActive, % WinT
ControlSend,, !eu, % WinT ;Reverts "Flatten".

MouseMove, % x, % y
:wave: There is always more than one way to solve a problem. ;)

Return to “Ask For Help”

Who is online

Users browsing this forum: JoeWinograd, Kellyzkorner_NJ, mad3d, mikeyww, Quisquose and 60 guests