Help with Variable Subtraction

Get help with using AutoHotkey and its commands and hotkeys
User avatar
ZoLatKam
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.
}
Return


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
jeeswg
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
var--
--var

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
YoucefHam
Posts: 344
Joined: 24 Aug 2015, 12:56
Facebook: https://fb.me/YoucefHamDz
Google: [email protected]
GitHub: YoucefHam
Location: Algeria
Contact:

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.
num1--
MouseGetPos, x, y
MouseMove, 0, 0
WinGetTitle, WinT, A
ControlSend, WindowsForms10.Window.8.app.0.2bf8098_r32_ad16, !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, WindowsForms10.Window.8.app.0.2bf8098_r32_ad15, ahk_exe PaintDotNet.exe ;Confirms "Flatten".

WinWaitActive, Save
Sleep, 450
ControlFocus, WindowsForms10.Window.8.app.0.2bf8098_r32_ad13, ahk_exe PaintDotNet.exe
ControlClick, WindowsForms10.Window.8.app.0.2bf8098_r32_ad13, ahk_exe PaintDotNet.exe ;Confirms Save


Sleep, 450
WinGetTitle, WinT, A
WinWaitActive, % WinT
ControlSend, WindowsForms10.Window.8.app.0.2bf8098_r32_ad16, !eu, % WinT ;Reverts "Flatten".

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

Return to “Ask For Help”

Who is online

Users browsing this forum: anv, Bing [Bot], DaveT1, Google [Bot], JoeWinograd, LakaiHigh, mikeyww, TheProdigyC2, TXShooter and 63 guests