Description:
* Allows you to change numeric values in edit controls by
dragging and/or scrolling the mouse wheel.
* Two modes for Dragging exist, up/down and left/right.
* Please see the comments of the functions aswell as the
demo code for more information.
dragging and/or scrolling the mouse wheel.
* Two modes for Dragging exist, up/down and left/right.
* Please see the comments of the functions aswell as the
demo code for more information.
Code: Select all
/*
Name: Wheel & Drag
Version 1.0 (Thu October 10, 2013)
Created: Thu October 10, 2013
Author: tidbit
Credit: AfterLemon - detecting a bug some people may or may not get.
Description:
* Allows you to change numeric values in edit controls by
dragging the mouse and/or scrolling the mouse wheel.
* Two modes for Dragging exist, up/down and left/right.
* Please see the comments of the functions aswell as the
demo code for more information.
*/
; /*
; -----------------
; --- DEMO CODE ---
; -----------------
; the only thing you need to do is add either (or both) of these 2 lines
; at the top of your script:
; OnMessage(WM_MOUSEWHEEL:=0x20A, "wheel")
; OnMessage(WM_MOUSEMOVE:=0x200, "drag")
#SingleInstance, force
Gui, font, s10, tahoma
Gui, add, text, xy y6 w500 cblue,
(ltrim join`s
This little demo contains 2 functions: Drag() and Wheel().
`n* Activate an edit control and scroll the mouse-wheel to change the value.
`n* Alternatively, Hold down the Left Mouse Button and drag the mouse up or down to
adjust the values.
`n* You may use ctrl to adjust the first decimal place (3.1) or shift to adjust
the second (3.14)
`n* Note: ComboBoxes seem to behave naughty.
)
Gui, font, s14, tahoma
Gui, add, edit, x6 y+2 w200 r1 vbanana, 34
Gui, add, edit, xp y+2 w180 r1 vdeer, 3.96
Gui, add, edit, xp y+2 w220 r1 vdesk, -0.21
Gui, add, edit, xp y+2 w300 r1 vaaa, whales.4
Gui, add, text, xp y+2 w300 r1 vbbb, 6795
Gui, add, comboBox, xp y+2 w200 r8 vccc, 111||222|333
Gui, show
OnMessage(WM_MOUSEWHEEL:=0x20A, "wheel")
OnMessage(WM_MOUSEMOVE:=0x200, "drag")
return
;*/
/*
drag
Allows you to click&hold then drag the mouse while an edit control is active
to adjust numeric values.
wParam - DO NOT TOUCH
lParam - Not used, but DO NOT TOUCH
You may use ctrl to adjust the first decimal place (3.1)
or shift to adjust the second (3.14) decimal.
example: there is none. Just place ... OnMessage(WM_MOUSEMOVE:=0x200, "drag") ... in your code.
*/
drag(wParam, lParam)
{
static yp,lastControl,change
sensitivity:=7 ; In pixels, about how far should the mouse move before adjusting the value?
amt:=1 ; How much to increase the value
mode:=1 ; 1 = up/down, 2=left/right
; some safety checks
if (!GetKeyState("Lbutton", "P"))
return
GuiControlGet, controlType, Focus
if (!instr(controlType, "Edit"))
return
GuiControlGet, value,, %A_GuiControl%
if value is not number
return
if (mode=1)
MouseGetPos,, y
else if (mode=2)
{
MouseGetPos, y
y*=-1 ; need to swap it so dragging to the right adds, not subtracts.
}
else
return
if (lastControl!=A_GuiControl) ; set the position to the current mouse position
yp:=y
change:=abs(y-yp) ; check to see if the value is ready to be changed, has it met the sensitivity?
mult:=((wParam=5) ? 0.01 : (wParam=9) ? 0.1 : 1)
value+=((y<yp && change>=sensitivity) ? amt*mult : (y>yp && change>=sensitivity) ? -amt*mult : 0)
GuiControl,, %A_GuiControl%, % RegExReplace(value, "(\.[1-9]+)0+$", "$1")
if (change>=sensitivity)
yp:=y
lastControl:=A_GuiControl
}
/*
wheel
Use MouseWheel Up and MouseWheel Down to adjust to adjust neumeric values.
wParam - DO NOT TOUCH
lParam - Not used, but DO NOT TOUCH
You may use ctrl to adjust the first decimal place (3.1)
or shift to adjust the second (3.14) decimal.
example: there is none. Just place ... OnMessage(WM_MOUSEWHEEL:=0x20A, "wheel") ... in your code.
*/
wheel(wParam, lParam)
{
amt:=1 ; How much to increase the value
GuiControlGet, controlType, Focus
if (!instr(controlType, "Edit"))
return
GuiControlGet, value,, %A_GuiControl%
if value is not number
return
mult:=((wParam & 0xffff=4) ? 0.01 : (wParam & 0xffff=8) ? 0.1 : 1)
value+=((StrLen(wParam)>7) ? -amt*mult : amt*mult)
GuiControl,, %A_GuiControl%, % RegExReplace(value, "(\.[1-9]+)0+$", "$1")
}
guiclose:
Esc::
critical
exitapp
return