Jump to content

GUI Button Repeat if Held Down


ViciousXUSMC
 Share

Recommended Posts

I made a gui for Spotify on my tablet.

Just using generic media keys like Send("{VOLUME_UP}")

The goal is that if I click and hold the button that sends Volume Up that it will repeat so I do not have to click it a hundred times.

So far while that seems like it should be really easy to do, its not working for me.

I tried _IsPressed("01") with no luck.  It does work if I use it with a keyboard key but not the 01 that should represent the left mouse button.

But there should be a better way to do it in the GUI/Case commands anyways.

 

Here is what I have right now.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIButton.au3>

FileInstall("VolDown.bmp", @TempDir & "\VolDown.bmp", 1)
FileInstall("Mute.bmp", @TempDir & "\Mute.bmp", 1)
FileInstall("VolUp.bmp", @TempDir & "\VolUp.bmp", 1)
FileInstall("Back.bmp", @TempDir & "\Back.bmp", 1)
FileInstall("Forward.bmp", @TempDir & "\Forward.bmp", 1)
FileInstall("Play.bmp", @TempDir & "\Play.bmp", 1)
FileInstall("Pause.bmp", @TempDir & "\Pause.bmp", 1)

AdLibRegister("KeepAlive", 60000)


#Region ### START Koda GUI section ### Form=C:\Users\it022565\Desktop\Media GUI\Form1.kxf
$Form1 = GUICreate("Patrick's Tablet Audio GUI", 621, 545, 192, 124)
$Button1 = GUICtrlCreateButton("VolDown", 56, 416, 90, 90, $BS_BITMAP)
GUICtrlSetImage(-1,  @TempDir & "\VolDown.bmp")
$Button2 = GUICtrlCreateButton("Mute", 269, 418, 90, 90, $BS_BITMAP)
GUICtrlSetImage(-1,  @TempDir & "\Mute.bmp")
$Button3 = GUICtrlCreateButton("VolUp", 493, 418, 90, 90, $BS_BITMAP)
GUICtrlSetImage(-1,  @TempDir & "\VolUp.bmp")
$Button4 = GUICtrlCreateButton("Back", 60, 223, 90, 90, $BS_BITMAP)
GUICtrlSetImage(-1,  @TempDir & "\Back.bmp")
$Button5 = GUICtrlCreateButton("Play", 225, 169, 180, 180, $BS_BITMAP)
GUICtrlSetImage(-1,  @TempDir & "\Pause.bmp")
$Button6 = GUICtrlCreateButton("Forward", 491, 222, 90, 90, $BS_BITMAP)
GUICtrlSetImage(-1,  @TempDir & "\Forward.bmp")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $vToggle = 1

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
                Send("{VOLUME_DOWN 5}")
        Case $Button2
            Send("{VOLUME_MUTE}")
        Case $Button3
            Send("{VOLUME_UP 5}")
        Case $Button4
            Send("{MEDIA_PREV}")
        Case $Button5
            Send("{MEDIA_PLAY_PAUSE}")
            $vToggle +=1
            If MOD($vToggle, 2) Then
                GUICtrlSetImage($Button5, @TempDir & "\Pause.bmp")
            Else
                GUICtrlSetImage($Button5, @TempDir & "\Play.bmp")
            EndIf
        Case $Button6
            Send("{MEDIA_NEXT}")
    EndSwitch
WEnd

Func KeepAlive()
    $aCurrentPos = MouseGetPos()
    MouseMove($aCurrentPos[0]+1, $aCurrentPos[1])
    MouseMove($aCurrentPos[0]-1, $aCurrentPos[1])
EndFunc

 

Link to comment
Share on other sites

I think there is a udf related to sound operations somewhere in the forum. 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

The GUIMsg isn't posted to your program until the left button is released. I don't know of any way to capture the message on a button when it's first clicked but you could try using a GUICtrlCreatePic control instead and use

GUIRegisterMsg($WM_LBUTTONDOWN, "WM_LBUTTONDOWN")

Func WM_LBUTTONDOWN($hWndFrom, $iMsg, $wParam, $lParam)
    Local $cursor_info = GUIGetCursorInfo()
    
    ; Check to see if the cursor is over the pic for volume up
    ; If the cursor is over the picture then go into a while loop that sends volume up
EndFunc

Something like that. That might do what you need. If that doesn't work (I don't have the time to write it and test it right now), worst case scenario you just use some GDI+ to create the buttons and use _WinAPI_PtInRectEx in the WM_LBUTTONDOWN function to test where the cursor is clicking.

Link to comment
Share on other sites

Alright, looks like the window message WM_LBUTTONDOWN isn't sent when you click on a control that's clickable (something like that) but using a CtrlPic you will get the GUIMsg when the left button is pressed before it's released (button you get the message after it's been released). This code will work if you use a CtrlPic instead of CtrlButton

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIButton.au3>
#include <WindowsConstants.au3>

FileInstall("VolDown.bmp", @TempDir & "\VolDown.bmp", 1)
FileInstall("Mute.bmp", @TempDir & "\Mute.bmp", 1)
FileInstall("VolUp.bmp", @TempDir & "\VolUp.bmp", 1)
FileInstall("Back.bmp", @TempDir & "\Back.bmp", 1)
FileInstall("Forward.bmp", @TempDir & "\Forward.bmp", 1)
FileInstall("Play.bmp", @TempDir & "\Play.bmp", 1)
FileInstall("Pause.bmp", @TempDir & "\Pause.bmp", 1)

AdLibRegister("KeepAlive", 60000)

#Region ### START Koda GUI section ### Form=C:\Users\it022565\Desktop\Media GUI\Form1.kxf
$Form1 = GUICreate("Patrick's Tablet Audio GUI", 621, 545, 192, 124)
$Button1 = GUICtrlCreateButton("VolDown", 56, 416, 90, 90, $BS_BITMAP)
GUICtrlSetImage(-1,  @TempDir & "\VolDown.bmp")
$Button2 = GUICtrlCreateButton("Mute", 269, 418, 90, 90, $BS_BITMAP)
GUICtrlSetImage(-1,  @TempDir & "\Mute.bmp")
$Button3 = GUICtrlCreatePic("\VolUp.bmp", 493, 418, 90, 90)
$Button4 = GUICtrlCreateButton("Back", 60, 223, 90, 90, $BS_BITMAP)
GUICtrlSetImage(-1,  @TempDir & "\Back.bmp")
$Button5 = GUICtrlCreateButton("Play", 225, 169, 180, 180, $BS_BITMAP)
GUICtrlSetImage(-1,  @TempDir & "\Pause.bmp")
$Button6 = GUICtrlCreateButton("Forward", 491, 222, 90, 90, $BS_BITMAP)
GUICtrlSetImage(-1,  @TempDir & "\Forward.bmp")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $vToggle = 1

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
                Send("{VOLUME_DOWN 5}")
        Case $Button2
            Send("{VOLUME_MUTE}")
        Case $Button3
            Local $cursor_info = GUIGetCursorInfo()

            If (Not @Error) Then
                If ($cursor_info[4] = $Button3) Then
                    While ($cursor_info[4] = $Button3 and $cursor_info[2])
                        Send("{VOLUME_UP 5}")
                        Sleep(200)
                        $cursor_info = GUIGetCursorInfo()

                        If (@Error) Then ExitLoop
                    WEnd
                EndIf
            EndIf
        Case $Button4
            Send("{MEDIA_PREV}")
        Case $Button5
            Send("{MEDIA_PLAY_PAUSE}")
            $vToggle +=1
            If MOD($vToggle, 2) Then
                GUICtrlSetImage($Button5, @TempDir & "\Pause.bmp")
            Else
                GUICtrlSetImage($Button5, @TempDir & "\Play.bmp")
            EndIf
        Case $Button6
            Send("{MEDIA_NEXT}")
    EndSwitch
WEnd

Func KeepAlive()
    $aCurrentPos = MouseGetPos()
    MouseMove($aCurrentPos[0]+1, $aCurrentPos[1])
    MouseMove($aCurrentPos[0]-1, $aCurrentPos[1])
EndFunc

You could also have a second bmp file for when the button is pressed to indicate that you're pressing it (or create a few labels to outline your picture and use GUICtrlSetPos to move them around the picture).

I'd still look into GDI+, could make something really pretty looking ;) lol

Edited by InunoTaishou
Link to comment
Share on other sites

My suggestion is to use SendMessage function with WM_APPCOMMAND. Here is the consts

Global Const APPCOMMAND_VOLUME_MUTE = 0x80000;
Global Const APPCOMMAND_VOLUME_UP = 0xA0000;
Global Const APPCOMMAND_VOLUME_DOWN = 0x90000;
Global Const WM_APPCOMMAND = 0x319;
SendMessageW(Your Window Handle, WM_APPCOMMAND,Your Window Handle, APPCOMMAND_VOLUME_UP)

Edit = I didn't tried this. Just a suggestion. :)

Edited by kcvinu
Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Inuno's idea worked really well.  Also showed me how to clean up the code some.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIButton.au3>
#include <WindowsConstants.au3>

FileInstall("VolDown.jpg", @TempDir & "\VolDown.jpg", 1)
FileInstall("Mute.jpg", @TempDir & "\Mute.jpg", 1)
FileInstall("VolUp.jpg", @TempDir & "\VolUp.jpg", 1)
FileInstall("Back.jpg", @TempDir & "\Back.jpg", 1)
FileInstall("Forward.jpg", @TempDir & "\Forward.jpg", 1)
FileInstall("Play.jpg", @TempDir & "\Play.jpg", 1)
FileInstall("Pause.jpg", @TempDir & "\Pause.jpg", 1)

AdLibRegister("KeepAlive", 60000)

#Region ### START Koda GUI section ### Form=C:\Users\it022565\Desktop\Media GUI\Form1.kxf
$Form1 = GUICreate("Patrick's Tablet Audio GUI", 621, 545, 192, 124)
$Button1 = GUICtrlCreatePic(@TempDir & "\VolDown.jpg", 56, 416, 90, 90)
$Button2 = GUICtrlCreatePic(@TempDir & "\Mute.jpg", 269, 418, 90, 90)
$Button3 = GUICtrlCreatePic(@TempDir & "\VolUp.jpg", 493, 418, 90, 90)
$Button4 = GUICtrlCreatePic(@TempDir & "\Back.jpg", 60, 223, 90, 90)
$Button5 = GUICtrlCreatePic(@TempDir & "\Play.jpg", 225, 169, 180, 180)
$Button6 = GUICtrlCreatePic(@TempDir & "\Forward.jpg", 491, 222, 90, 90)
$Button7 = GUICtrlCreatePic("Spotify.jpg", 260, 20, 110, 110)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $vToggle = 1

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
             Local $cursor_info = GUIGetCursorInfo()
            If (Not @Error) Then
                If ($cursor_info[4] = $Button1) Then
                    While ($cursor_info[4] = $Button1 and $cursor_info[2])
                        Send("{VOLUME_DOWN}")
                        Sleep(100)
                        $cursor_info = GUIGetCursorInfo()
                        If (@Error) Then ExitLoop
                    WEnd
                EndIf
            EndIf
        Case $Button2
            Send("{VOLUME_MUTE}")
        Case $Button3
            Local $cursor_info = GUIGetCursorInfo()
            If (Not @Error) Then
                If ($cursor_info[4] = $Button3) Then
                    While ($cursor_info[4] = $Button3 and $cursor_info[2])
                        Send("{VOLUME_UP}")
                        Sleep(100)
                        $cursor_info = GUIGetCursorInfo()
                        If (@Error) Then ExitLoop
                    WEnd
                EndIf
            EndIf
        Case $Button4
            Send("{MEDIA_PREV}")
        Case $Button5
            Send("{MEDIA_PLAY_PAUSE}")
            $vToggle +=1
            If MOD($vToggle, 2) Then
                GUICtrlSetImage($Button5, @TempDir & "\Pause.bmp")
            Else
                GUICtrlSetImage($Button5, @TempDir & "\Play.bmp")
            EndIf
        Case $Button6
            Send("{MEDIA_NEXT}")
        Case $Button7
            If ProcessExists("Spotify.exe") Then
                ProcessClose("Spotify.exe")
            Else
                ShellExecute(@UserProfileDir & "\AppData\Roaming\Spotify\Spotify.exe")
            EndIf
                EndSwitch
WEnd

Func KeepAlive()
    $aCurrentPos = MouseGetPos()
    MouseMove($aCurrentPos[0]+1, $aCurrentPos[1])
    MouseMove($aCurrentPos[0]-1, $aCurrentPos[1])
EndFunc

 

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