UpDown with decimal variables (use Shift)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Snowy42
Posts: 42
Joined: 03 Jul 2017, 18:32

UpDown with decimal variables (use Shift)

Post by Snowy42 » 23 Mar 2023, 16:18

Hi all,

I'm trying to work out how to do this... I have some code that allows me to use the UpDown control to change values by 0.1 increments. It's pretty simple but it works. I'm now trying to add functionality to jump by larger values if the user is holding shift.

Here's the code that allows me to do the updown by 0.1:

Code: Select all

Gui, add, edit, w100 vTest_Variable
Gui, add, updown, vTest_Variable_UD gTest_Action_UD
Gui, Show
return

Test_Action_UD:
	Gui, Submit, NoHide
	Test_Control := StrReplace(A_GuiControl, "_UD")
	decVal := (%Test_Control% / 10)
	GuiControl,, % Test_Control, % Format("{1:0.1f}", decVal)
return
I've then tried to add a check variable to see if the user is holding shift with isShiftDown := GetKeyState("Shift") and then adjust the decVal variable by a whole number with something like decVal := (%Test_Control% / 10) + ((isShiftDown)?0.9:0). I know this doesn't consider if the user presses down instead, but i'm just trying to test the concept at the moment.

These adjustments will make it work for the FIRST "up" press, i.e. it will change from 0.2 to 1.2, but then even if holding shift, it will just continue to 1.3, 1.4, etc. then when I stop holding shift, it will jump back down to 0.5.

I know it's probably something simple, I just can't seem to figure out the logic! Please help... I've been stuck on this for hours!


[Mod action: Topic moved from "Ask for Help (v2)" since this is v1 code.]

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

Re: UpDown with decimal variables (use Shift)

Post by mikeyww » 23 Mar 2023, 17:17

Code: Select all

#Requires AutoHotkey v1.1.33
Global ed := 0, notch := 0
Gui Font, s10
Gui Add, Edit  , ved    w230
Gui Add, UpDown, vnotch gadjust
Gui Show
Return

adjust() {
 Static last := 0, value := 0
 Gui Submit, NoHide
 GuiControl ,, ed, % Format("{:.1f}", value += (notch - last) * (0.9 * GetKeyState("Shift", "P") + 0.1))
 last := notch
}

Post Reply

Return to “Ask for Help (v1)”