Jump to content

Slider with MoueOnEvent.au3


kara2004
 Share

Recommended Posts

Hi there,

while looking around to control sliders with the mouse wheeI I found MouseOnEvent.au3 which seems to fit my needs.

But there's a strange behaviour, which I can't locate (my env Win 7x64 with au3 3.3.14.5, the UDF or the slider itself): Using the mouse wheel to change the slider the value shown/set is always "one step behind".

I made a simple gui with one slider (limit -10 to 10) and after ten wheel moves the slider looks correct, but the label shows '9' (see picture "slider_1.jpg" which shows the gui after 10 wheel moves). A manual mouse click at the slider control at this time adjusts the label to the correct value (see picture "slider_2.jpg") but using the wheel ro get a value of "10" (or -10) I have to scroll eleven times. The UDF seems to work correct, every event is recognized (checked with additional debug messages added), controlling the slider with arrow keys or direct via left mouse button shows the correct value at the label.

Probably it's just a simple problem with the code, but I have no idea for getting the expected behaviour (Note: I renamed the udf to '_MouseOnEvent.au3' to get all udfs togeter in my code directory).

Thanks for any suggestion or correction.

kara

 

#include <_MouseOnEvent.au3>

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 567, 148, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
Global $Slider1 = GUICtrlCreateSlider(8, 8, 497, 33)
GUICtrlSetLimit(-1, 10, -10)
GUICtrlSetData(-1, 0)
GUICtrlSetOnEvent(-1, "Slider1Change")
Global $Label1 = GUICtrlCreateLabel("", 512, 8, 36, 17)

GUICtrlSetData($Label1, GUICtrlRead($Slider1))

_MouseSetOnEvent($MOUSE_WHEELSCROLLUP_EVENT, "MOUSE_WHELLSCROLL_UP", $Form1)
_MouseSetOnEvent($MOUSE_WHEELSCROLLDOWN_EVENT, "MOUSE_WHELLSCROLL_DOWN", $Form1)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

_sciteClearConsole()

While 1
    Sleep(100)
WEnd

Exit

Func Form1Close()
    Exit
EndFunc   ;==>Form1Close

Func Slider1Change()
    ConsoleWrite("SL_CHNG:" & GUICtrlRead($Slider1) & @CRLF)
    GUICtrlSetData($Label1, GUICtrlRead($Slider1))
EndFunc   ;==>Slider1Change

Func MOUSE_WHELLSCROLL_UP()
    ConsoleWrite("SCRL_UP:" & GUICtrlRead($Slider1) & @CRLF)
    GUICtrlSetData($Label1, GUICtrlRead($Slider1))
EndFunc   ;==>MOUSE_WHELLSCROLL_UP

Func MOUSE_WHELLSCROLL_DOWN()
    ConsoleWrite("SCRL_DOWN:" & GUICtrlRead($Slider1) & @CRLF)
    GUICtrlSetData($Label1, GUICtrlRead($Slider1))
EndFunc   ;==>MOUSE_WHELLSCROLL_DOWN

 

Slider_1.jpg

Slider_2.jpg

Link to comment
Share on other sites

Opt ("GUIOnEventMode", 1)

is missing at the top of your script...

GUICtrlSetState ($Slider1, $GUI_FOCUS)

Maybe for some reason, you are loosing focus on the slider so add this line in both up and down functions.

Edited by Nine
Link to comment
Share on other sites

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <File.au3>
#include <Array.au3>
#include <WinAPI.au3>
#include <String.au3>
#include <Timers.au3>
#include <GuiEdit.au3>
#include <GDIPlus.au3>
#include <Process.au3>
#include <WinAPIEx.au3>
#include <WinAPISys.au3>
#include <GuiButton.au3>
#include <Constants.au3>
#include <GuiSlider.au3>
#include <WinAPISys.au3>
#include <WinAPIMisc.au3>
#include <GuiToolTip.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <GUIConstants.au3>
#include <GuiImageList.au3>
#include <TrayConstants.au3>
#include <FileConstants.au3>
#include <GuiComboBoxEx.au3>
#include <GUIConstantsEx.au3>
#include <APISysConstants.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <SliderConstants.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 567, 148, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
Global $Slider1 = GUICtrlCreateSlider(8, 8, 497, 33)
GUICtrlSetLimit($Slider1, 10, -10)
GUICtrlSetData($Slider1, 0)
Global $Label1 = GUICtrlCreateLabel("", 512, 8, 36, 17)
;=============================================================================
Local $iFlags, $aData
Local $tRID = DllStructCreate($tagRAWINPUTDEVICE)
DllStructSetData($tRID, 'UsagePage', 0x01) ; Generic Desktop Controls
DllStructSetData($tRID, 'Usage', 0x02) ; Mouse
DllStructSetData($tRID, 'Flags', $RIDEV_INPUTSINK)
DllStructSetData($tRID, 'hTarget', $Form1)
_WinAPI_RegisterRawInputDevices($tRID)
GUIRegisterMsg($WM_INPUT, 'WM_INPUT')
;=============================================================================
GUICtrlSetData($Label1, GUICtrlRead($Slider1))

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
    GUICtrlSetData($Label1, GUICtrlRead($Slider1))
WEnd

Func Form1Close()
    Exit
EndFunc   ;==>Form1Close

Func MOUSE_WHELLSCROLL_UP()
    ConsoleWrite("SCRL_UP:" & GUICtrlRead($Slider1) & @CRLF)
    GUICtrlSetData($Label1, GUICtrlRead($Slider1))
EndFunc   ;==>MOUSE_WHELLSCROLL_UP

Func MOUSE_WHELLSCROLL_DOWN()
    ConsoleWrite("SCRL_DOWN:" & GUICtrlRead($Slider1) & @CRLF)
    GUICtrlSetData($Label1, GUICtrlRead($Slider1))
EndFunc   ;==>MOUSE_WHELLSCROLL_DOWN

;=============================================================================
Func WM_INPUT($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    If WinActive("[CLASS:YOURWINDOWCLASS]") <> 0 Then
            Local $tRIM = DllStructCreate($tagRAWINPUTMOUSE)
            If _WinAPI_GetRawInputData($lParam, $tRIM, DllStructGetSize($tRIM), $RID_INPUT) Then
                $iFlags = DllStructGetData($tRIM, 'ButtonFlags')
                If BitAND($iFlags, $RI_MOUSE_WHEEL) Then
                    $aData = _WinAPI_WordToShort(DllStructGetData($tRIM, 'ButtonData'))
                    If $aData > 0 Then
                        ;ConsoleWrite(' - Up - '&@CRLF)
                MOUSE_WHELLSCROLL_UP()
                    Else
                        ;ConsoleWrite(' - Down - '&@CRLF)
                MOUSE_WHELLSCROLL_DOWN()
                    EndIf
                Else
                    ToolTip('')
                EndIf
            EndIf
    Return $GUI_RUNDEFMSG
    EndIf
    Return $GUI_RUNDEFMSG
    Sleep(50)
EndFunc   ;==>WM_INPUT

 

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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...