Jump to content

UpDown - How to slow it down a bit?


 Share

Recommended Posts

Hi,

When you press and hold the UpDown arrow, with the mouse or the arrow keys of the keyboard it is increasing or decreasing the $input1 number way too fast. It is even getting faster and faster the more you keep the arrow pressed.

So...Is it possible to get the increase and decrease slower and constant?

Thanks!

Alain

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <UpdownConstants.au3>
 
$Form1  = GUICreate("Test UpDown", 288, 284,-1,-1)
$Input1 = GUICtrlCreateInput("", 92, 116, 57, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_RIGHT))
$Input2= GUICtrlCreateInput("0", 155, 116, 15, 21)
$Updown = GUICtrlCreateUpdown($Input2,$UDS_ARROWKEYS)
 
GUISetState(@SW_SHOW)
GUICtrlSetState ( $Input2, $GUI_FOCUS )
 
$Actual=100
_Display_It()
 
While 1
$nMsg = GUIGetMsg()
 
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  case $input2
   $Actual=Number(GUICtrlRead($input1)) + (Number(GUICtrlRead($input2))*0.01)
   _Display_It()
   GUICtrlSetData($input2, 0)
EndSwitch
 
WEnd
 
Func _Display_It()
GUICtrlSetData($input1,  StringFormat("%#.2f $", $Actual))
EndFunc
Edited by AlainB
Link to comment
Share on other sites

I have no idea how, or indeed if you can implement this in Autoit, but its somewhere you can look.

I think its possible a message you can send to set the acceleration.

http://msdn.microsoft.com/en-us/library/windows/desktop/bb759941%28v=vs.85%29.aspx

EDIT:

Take a look at post #3 in this thread.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

This piqued my interest so I had a try to include the above linked function into your example gui.

It certainly regulates the acceleration somewhat, but not as I expected.

In the linked example when modified to increment by 1 with no acceleration it does just that, but does not seem to perform the same in your gui.

I will assume its something to do with the decimal places, I don't really know,

Anyway.

;example script using _GUICtrlUpdownSetAccel()
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <GUIComboBox.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <UpdownConstants.au3>
$Form1 = GUICreate("Test UpDown", 288, 284, -1, -1)
$Input1 = GUICtrlCreateInput("", 92, 116, 57, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_RIGHT))
$Input2 = GUICtrlCreateInput("0", 155, 116, 15, 21)
$Updown = GUICtrlCreateUpdown($Input2, $UDS_ARROWKEYS)
GUISetState(@SW_SHOW)
GUICtrlSetState($Input2, $GUI_FOCUS)
$Actual = 100
_Display_It()
; Set The acceleration here
; increment by 1 until 10 seconds have past, then increment by 10
$nSec1 = "0|10"; 0 seconds to 10 seconds
$nInc1 = "1|10"; increment by 1 the 10
_GUICtrlUpdownSetAccel($Updown, $nSec1, $nInc1)
If @error Then
MsgBox(1, "Error", @error)
Exit
EndIf
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Input2
   $Actual = Number(GUICtrlRead($Input1)) + (Number(GUICtrlRead($Input2)) * 0.01)
   _Display_It()
   GUICtrlSetData($Input2, 0)
EndSwitch
WEnd
Func _Display_It()
Sleep(10)
GUICtrlSetData($Input1, StringFormat("%#.2f $", $Actual))
EndFunc   ;==>_Display_It
;===============================================================================
;
; Description:    _GUICtrlUpdownSetAccel
; Parameter(s):  $h_updown - updown controlID
;                  $nSecList - "|" delimited list of nSec times (Default "0|2|5" )
;                  $nIncList - "|" delimited list of nInc increment (Default "1|5|20" )
;                              after 0 seconds, updown increments by 1
;                              after 1 second, updown increments by 5
;                              after 5 seconds, updown increments by 20
; Requirement:    <GUIConstants.au3>
; Return Value(s):  Returns nonzero if successful, or zero otherwise.
;                          If an error occurs, the return value is $LV_ERR (-1) and @error is set to -1
; User CallTip:  _GUICtrlUpdownSetAccel ( $h_updown ) resets to default values in example above
;                  _GUICtrlUpdownSetAccel ( $h_updown, "0", "10" ) makes the updown increment by 10 with no acceleration
;                 _GUICtrlUpdownSetAccel ( $h_updown, "0|2", "1|10" ) makes the updown increment by 1. After 2 seconds, it increments by 10
; Author(s):        Chris Howes (OjO)
; Note(s):        $nSecList and $nIncList must have the same number of delimited values
;                  $nSecList must be in increasing order ex: "0|7|8"  - using "0|8|7" would fail and return -1
;                  string values in $nSecList and $nIncList must have integer value of 0 or greater
;
;===============================================================================
Func _GUICtrlUpdownSetAccel($h_updown = 0, $nSecList = "0|2|5", $nIncList = "1|5|20"); 0|2|5 and 1|5|20 are default windows settings
Const $UDM_SETACCEL = $WM_USER + 107
Local $nSecErr = 0
Local $nSec = StringSplit($nSecList, "|")
Local $nInc = StringSplit($nIncList, "|")
Local $x = 0
If $nSec[0] <> $nInc[0] Then Return SetError($CB_ERR, $CB_ERR, $CB_ERR);check for same # of nSec & nInc sets
For $x = 1 To $nSec[0];check for non integers, and negative numbers, and zero length entries
  If StringIsInt($nSec[$x]) = 0 Or Int($nSec[$x]) < 0 Or StringLen($nSec[$x]) = 0 Then Return SetError($CB_ERR, $CB_ERR, $CB_ERR)
  If StringIsInt($nInc[$x]) = 0 Or Int($nInc[$x]) < 0 Or StringLen($nInc[$x]) = 0 Then Return SetError($CB_ERR, $CB_ERR, $CB_ERR)
Next
If $nSec[0] > 1 Then
  For $x = 2 To $nSec[0]
   If $nSec[$x] <= $nSec[$x - 1] Then $nSecErr = 1;check for ascending order of nSec sequence
  Next
  If $nSecErr = 1 Then Return SetError($CB_ERR, $CB_ERR, $CB_ERR)
EndIf
Local $str = "uint;uint";create initial structure for set of nSec;nInc
If $nSec[0] > 1 Then ;add more structure for additional entries
  For $x = 2 To $nSec[0]
   $str = $str & ";uint;uint"
  Next
EndIf
Local $AccelStruct = DllStructCreate($str)
For $x = 1 To $nSec[0];Put Data in the structure
  DllStructSetData($AccelStruct, ($x * 2) - 1, Number($nSec[$x]))
  DllStructSetData($AccelStruct, ($x * 2), Number($nInc[$x]))
Next
If IsHWnd($h_updown) Then
  Local $a_ret = DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_updown, "int", $UDM_SETACCEL, "int", $nSec[0], "ptr", DllStructGetPtr($AccelStruct))
  Return $a_ret[0]
Else
  GUICtrlSendMsg($h_updown, $UDM_SETACCEL, $nSec[0], DllStructGetPtr($AccelStruct))
EndIf
EndFunc   ;==>_GUICtrlUpdownSetAccel

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Hi,

When you press and hold the UpDown arrow, with the mouse or the arrow keys of the keyboard it is increasing or decreasing the $input1 number way too fast. It is even getting faster and faster the more you keep the arrow pressed.

So...Is it possible to get the increase and decrease slower and constant?

Thanks!

Alain

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <UpdownConstants.au3>
 
$Form1  = GUICreate("Test UpDown", 288, 284,-1,-1)
$Input1 = GUICtrlCreateInput("", 92, 116, 57, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_RIGHT))
$Input2= GUICtrlCreateInput("0", 155, 116, 15, 21)
$Updown = GUICtrlCreateUpdown($Input2,$UDS_ARROWKEYS)
 
GUISetState(@SW_SHOW)
GUICtrlSetState ( $Input2, $GUI_FOCUS )
 
$Actual=100
_Display_It()
 
While 1
$nMsg = GUIGetMsg()
 
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  case $input2
   $Actual=Number(GUICtrlRead($input1)) + (Number(GUICtrlRead($input2))*0.01)
   _Display_It()
   GUICtrlSetData($input2, 0)
EndSwitch
 
WEnd
 
Func _Display_It()
GUICtrlSetData($input1,  StringFormat("%#.2f $", $Actual))
EndFunc

I have writed a UDF for Updown control!

try following code:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <UpdownConstants.au3>
#include "_GUICtrlUpdown.au3"
$Form1  = GUICreate("Test UpDown", 288, 284,-1,-1)
$Input1 = GUICtrlCreateInput("", 92, 116, 57, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_RIGHT))
$Input2= GUICtrlCreateInput("0", 155, 116, 15, 21)
$Updown = GUICtrlCreateUpdown($Input2,$UDS_ARROWKEYS)
Local $aUDACCEL[1][2] = [[0, 1]]
_GUICtrlUpdown_SetAccel($Updown, $aUDACCEL) ;Now It's constant:1 for increase and decrease
GUISetState(@SW_SHOW)
GUICtrlSetState ( $Input2, $GUI_FOCUS )

$Actual=100
_Display_It()

While 1
$nMsg = GUIGetMsg()

Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  case $input2
   $Actual=Number(GUICtrlRead($input1)) + (Number(GUICtrlRead($input2))*0.01)
   _Display_It()
   GUICtrlSetData($input2, 0)
EndSwitch

WEnd

Func _Display_It()
GUICtrlSetData($input1,  StringFormat("%#.2f $", $Actual))
EndFunc

_GUICtrlUpdown.au3

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...