Jump to content

Mimic Keyboard input with slider


Recommended Posts

I am trying to create a simple gui for a command line player "MPXPLAY".

The volume increases or decreases on pressing "." or "," respectively on the keyboard. I want to mimic this i.e. increase/decrease the volume using a slider in the gui. How do I do it?

#include <GUIConstantsEx.au3>
Global $select_file, $select_exe, $input_file, $input_exe
Opt("GUIOnEventMode", 1)

GUICreate("MPXPLAY GUI", 370, 160)
GUISetState()

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
Func CLOSEClicked()
    Exit
EndFunc  ;==>CLOSEClicked

;---------------------------ALL BUTTONS--------------------------------------
$browsebutton_exe = GUICtrlCreateButton("Browse", 270, 20, 70, 20) 
GUICtrlSetOnEvent($browsebutton_exe, "BROWSEButton_exe")

$browsebutton_file = GUICtrlCreateButton("Browse", 270, 60, 70, 20)
GUICtrlSetOnEvent($browsebutton_file, "BROWSEButton_file")

$input_exe = GUICtrlCreateInput("Put MPXPLAY.exe here", 40, 20, 220, 20)
$input_file = GUICtrlCreateInput("Put audio file here", 40, 60, 220, 20)

GUICtrlCreateLabel("Volume", 40, 90) 
GUICtrlCreateSlider(80, 90, 200, 20) 

$okbutton = GUICtrlCreateButton("OK", 30, 120, 80, 20)
GUICtrlSetOnEvent($okbutton, "OKButton")

$playbutton = GUICtrlCreateButton("PLAY/PAUSE", 110, 120, 80, 20)
GUICtrlSetOnEvent($playbutton, "PLAYButton")

$stopbutton = GUICtrlCreateButton("STOP", 190, 120, 80, 20)
GUICtrlSetOnEvent($stopbutton, "STOPButton")

$exitbutton = GUICtrlCreateButton("EXIT", 270, 120, 70, 20)
GUICtrlSetOnEvent($exitbutton, "EXITButton")
;--------------------------------------------------------------------------

Func BROWSEButton_exe()
 $select_exe = FileOpenDialog("Browse MPXPLAY.exe", "C:\", "(*.exe)")
GUICtrlSetData($input_exe, $select_exe)
EndFunc

Func BROWSEButton_file()
 $select_file = FileOpenDialog("Browse the audio file", "C:\", "(*.mp3)")
GUICtrlSetData($input_file, $select_file)
EndFunc

While 1
    Sleep(1000)
WEnd

Func OKButton()
    Local $n8 = '"' & $select_exe & '" ' & '"' & $select_file & '"'
    Run($n8)
EndFunc  ;==>OKButton

Func PLAYButton()
    WinActivate("Mpxplay")
    Send("{P}")
EndFunc   ;==>PLAYButton

Func STOPButton()
    WinActivate("Mpxplay")
    Send("{S}")
    EndFunc  ;==>STOPButton

Func EXITButton()
    WinActivate("Mpxplay")
    Send("{Esc}")
    Exit
EndFunc  ;==>EXITButton
Edited by ontherocks
Link to comment
Share on other sites

Something like this maybe

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)
Global $slider1
Global $slide = 0
Global $stepsperinc = 2;set how many . or , are sent for a change in the slider
Example()


Func Example()
    Local $button, $msg

    GUICreate("slider", 220, 100, 100, 200)
    GUISetBkColor(0x00E0FFFF); will change background color

    $slider1 = GUICtrlCreateSlider(10, 10, 200, 20)
    GUICtrlSetLimit(-1, 200, 0); change min/max value
    $button = GUICtrlCreateButton("Value?", 75, 70, 70, 20)
    GUISetState()
    GUICtrlSetData($slider1, 45); set cursor
    AdlibEnable("volupdate", 100)
    Do
        $msg = GUIGetMsg()

        If $msg = $button Then
            MsgBox(0, "slider1", GUICtrlRead($slider1), 2)
        EndIf
    Until $msg = $GUI_EVENT_CLOSE
EndFunc  ;==>Example

Func volupdate()
    Local $nowslider = GUICtrlRead($slider1)
    If $nowslider < $slide Then
        Send("{. " & Int(($slide - $nowslider) / $stepsperinc & "}")
    ElseIf $nowslider > $slide Then
        Send("{, " & Int(($nowslider - $slide) / $stepsperinc) & "}")
    EndIf
    $slide = $nowslider
EndFunc  ;==>volupdate
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Thanks a lot martin. I was able to advance further.

The issue now is as follows:-

The dos window of the player has to be on top & activated for any key to work. Hence with the code below, the increments in slider does not work in parallel to the increase in dos window.

It happens in kind of jumps. I move the slider->the dos window activates->the volume increases/decreases->but the GUI deactivates. So I have to activate the GUI by clicking with mouse and then repeat the above process.

I am not sure if both the GUI and dos window can be activated simultaneously. Or if the dos window can be put/hidden in background but the keys would still work.

#include <GUIConstantsEx.au3>
#Include <GuiSlider.au3>

Global $slider_value, $slide
Global $select_file, $select_exe, $input_file, $input_exe, $browsebutton_exe, $browsebutton_file
Global $okbutton, $playbutton, $stopbutton, $exitbutton

Opt("GUIOnEventMode", 1)
GUICreate("MPXPLAY GUI", 370, 160)
GUISetState()

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
Func CLOSEClicked()
    Exit
EndFunc  ;==>CLOSEClicked
;--------------------------------------------------------------------------
$browsebutton_exe = GUICtrlCreateButton("Browse", 270, 20, 70, 20) 
GUICtrlSetOnEvent($browsebutton_exe, "BROWSEButton_exe")

$browsebutton_file = GUICtrlCreateButton("Browse", 270, 60, 70, 20)
GUICtrlSetOnEvent($browsebutton_file, "BROWSEButton_file")

$input_exe = GUICtrlCreateInput("Put MPXPLAY.exe here", 40, 20, 220, 20)
$input_file = GUICtrlCreateInput("Put audio file here", 40, 60, 220, 20)

GUICtrlCreateLabel("Volume", 40, 90) 
$slider_value = GUICtrlCreateSlider(80, 90, 200, 20, $TBS_TOOLTIPS) 
GUICtrlSetLimit($slider_value, 200, 0)
GUICtrlSetData($slider_value, 100)

$okbutton = GUICtrlCreateButton("OK", 30, 120, 80, 20)
GUICtrlSetOnEvent($okbutton, "OKButton")

$playbutton = GUICtrlCreateButton("PLAY/PAUSE", 110, 120, 80, 20)
GUICtrlSetOnEvent($playbutton, "PLAYButton")

$stopbutton = GUICtrlCreateButton("STOP", 190, 120, 80, 20)
GUICtrlSetOnEvent($stopbutton, "STOPButton")

$exitbutton = GUICtrlCreateButton("EXIT", 270, 120, 70, 20)
GUICtrlSetOnEvent($exitbutton, "EXITButton")
;--------------------------------------------------------------------------
Func BROWSEButton_exe()
 $select_exe = FileOpenDialog("Browse MPXPLAY.exe", "C:\", "(*.exe)")
GUICtrlSetData($input_exe, $select_exe)
EndFunc

Func BROWSEButton_file()
 $select_file = FileOpenDialog("Browse the audio file", "C:\", "(*.mp3)")
GUICtrlSetData($input_file, $select_file)
EndFunc

Func OKButton()
    Local $n8 = '"' & $select_exe & '" ' & '"' & $select_file & '"'
    Run($n8)
EndFunc  ;==>OKButton

AdlibEnable("volupdate", 100)

Func volupdate()

Local $nowslider = GUICtrlRead($slider_value)
    If $nowslider < $slide Then
        WinActivate("Mpxplay")
        Send("{, " & Int(($slide - $nowslider)/2) & "}")
    ElseIf $nowslider > $slide Then
        WinActivate("Mpxplay")
        Send("{. " & Int(($nowslider - $slide)/2) & "}")
    EndIf
   $slide = $nowslider
    
EndFunc  ;==>volupdate

Func PLAYButton()
    WinActivate("Mpxplay")
    Send("{P}")
EndFunc   ;==>PLAYButton

Func STOPButton()
    WinActivate("Mpxplay")
    Send("{S}")
    EndFunc  ;==>STOPButton

Func EXITButton()
    WinActivate("Mpxplay")
    Send("{Esc}")
    Exit
EndFunc  ;==>EXITButton


While 1
   Sleep(1000)
WEnd
Link to comment
Share on other sites

Thanks a lot martin. I was able to advance further.

The issue now is as follows:-

The dos window of the player has to be on top & activated for any key to work. Hence with the code below, the increments in slider does not work in parallel to the increase in dos window.

It happens in kind of jumps. I move the slider->the dos window activates->the volume increases/decreases->but the GUI deactivates. So I have to activate the GUI by clicking with mouse and then repeat the above process.

I am not sure if both the GUI and dos window can be activated simultaneously. Or if the dos window can be put/hidden in background but the keys would still work.

#include <GUIConstantsEx.au3>
#Include <GuiSlider.au3>

Global $slider_value, $slide
Global $select_file, $select_exe, $input_file, $input_exe, $browsebutton_exe, $browsebutton_file
Global $okbutton, $playbutton, $stopbutton, $exitbutton

Opt("GUIOnEventMode", 1)
GUICreate("MPXPLAY GUI", 370, 160)
GUISetState()

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
Func CLOSEClicked()
    Exit
EndFunc  ;==>CLOSEClicked
;--------------------------------------------------------------------------
$browsebutton_exe = GUICtrlCreateButton("Browse", 270, 20, 70, 20) 
GUICtrlSetOnEvent($browsebutton_exe, "BROWSEButton_exe")

$browsebutton_file = GUICtrlCreateButton("Browse", 270, 60, 70, 20)
GUICtrlSetOnEvent($browsebutton_file, "BROWSEButton_file")

$input_exe = GUICtrlCreateInput("Put MPXPLAY.exe here", 40, 20, 220, 20)
$input_file = GUICtrlCreateInput("Put audio file here", 40, 60, 220, 20)

GUICtrlCreateLabel("Volume", 40, 90) 
$slider_value = GUICtrlCreateSlider(80, 90, 200, 20, $TBS_TOOLTIPS) 
GUICtrlSetLimit($slider_value, 200, 0)
GUICtrlSetData($slider_value, 100)

$okbutton = GUICtrlCreateButton("OK", 30, 120, 80, 20)
GUICtrlSetOnEvent($okbutton, "OKButton")

$playbutton = GUICtrlCreateButton("PLAY/PAUSE", 110, 120, 80, 20)
GUICtrlSetOnEvent($playbutton, "PLAYButton")

$stopbutton = GUICtrlCreateButton("STOP", 190, 120, 80, 20)
GUICtrlSetOnEvent($stopbutton, "STOPButton")

$exitbutton = GUICtrlCreateButton("EXIT", 270, 120, 70, 20)
GUICtrlSetOnEvent($exitbutton, "EXITButton")
;--------------------------------------------------------------------------
Func BROWSEButton_exe()
 $select_exe = FileOpenDialog("Browse MPXPLAY.exe", "C:\", "(*.exe)")
GUICtrlSetData($input_exe, $select_exe)
EndFunc

Func BROWSEButton_file()
 $select_file = FileOpenDialog("Browse the audio file", "C:\", "(*.mp3)")
GUICtrlSetData($input_file, $select_file)
EndFunc

Func OKButton()
    Local $n8 = '"' & $select_exe & '" ' & '"' & $select_file & '"'
    Run($n8)
EndFunc  ;==>OKButton

AdlibEnable("volupdate", 100)

Func volupdate()

Local $nowslider = GUICtrlRead($slider_value)
    If $nowslider < $slide Then
        WinActivate("Mpxplay")
        Send("{, " & Int(($slide - $nowslider)/2) & "}")
    ElseIf $nowslider > $slide Then
        WinActivate("Mpxplay")
        Send("{. " & Int(($nowslider - $slide)/2) & "}")
    EndIf
   $slide = $nowslider
    
EndFunc  ;==>volupdate

Func PLAYButton()
    WinActivate("Mpxplay")
    Send("{P}")
EndFunc   ;==>PLAYButton

Func STOPButton()
    WinActivate("Mpxplay")
    Send("{S}")
    EndFunc  ;==>STOPButton

Func EXITButton()
    WinActivate("Mpxplay")
    Send("{Esc}")
    Exit
EndFunc  ;==>EXITButton


While 1
   Sleep(1000)
WEnd
Maybe if you used

$mxPID = $Run($n8,@SystemDir, @SW_HIDE, $STDIN_CHILD )

then you could use

StdinWrite($mxPID, "." )
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Thanks a bunch marin. :)

I tried your earlier suggestion using ControlSend and it worked great. The only problem was that the volume control using the slider was not smooth enough.

Now you have suggested a StdinWrite. Is this to substitute Controlsend?

I am getting errors using StdinWrite which I can't decipher.

Link to comment
Share on other sites

Thanks a bunch marin. :)

I tried your earlier suggestion using ControlSend and it worked great. The only problem was that the volume control using the slider was not smooth enough.

Now you have suggested a StdinWrite. Is this to substitute Controlsend?

I am getting errors using StdinWrite which I can't decipher.

The StdinWrite idea was to replace the ControlSend which I thought about after I'd posted it and decided it probably wouldn't work. Looks like I'm wrong both times! What errors do you get?
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

There were some silly syntax errors, which I corrected.

Strangely with the "Run" function in this case, both "@SW_HIDE, $STDIN_CHILD" don't work i.e. the mpxplay exe doesn't run.

Either I have to put

Run($n8, "", @SW_HIDE) or Run($n8, "", $STDIN_CHILD)

Its still not clear to me how to replace ControlSend with StdinWrite.

For example, I tried something like

Func PLAYButton()
    $n9="{P}"
     StdinWrite ($mxPID, $n9)
EndFunc  ;==>PLAYButton

But then nothing happens on clicking Play Button

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