Sign in to follow this  
Followers 0
ezzetabi

My little program...

5 posts in this topic

If WinExists('Ready to use command line.') Then Exit
AutoItWinSetTitle('Ready to use command line.')



Opt ('TrayIconHide', 1)
Opt ('GUITaskbarEntry', 0)
_SetConstants()
Opt ('MustDeclareVars', 1)

Dim $COMMONSTYLE, $COMMONSTYLEEX, $EDITSTYLE, $BUTTONSTYLE ;Styles related
Dim $INPUT = '', $CTR_INPUT                             ;Input related
Dim $CTR_OK, $CTR_OPEN, $CTR_VUP, $CTR_VDOWN, $CTR_VZERO     ;Buttons related

While 1
   
   $COMMONSTYLE = $WS_MINIMIZEBOX + $WS_GROUP + $WS_POPUP
   
   If IniRead('settings.ini', 'main', 'alwaysontop', 0) = 1 Then 
      $COMMONSTYLEEX = $WS_EX_TOPMOST + $WS_EX_ACCEPTFILES
   Else
      $COMMONSTYLEEX = $WS_EX_ACCEPTFILES
   EndIf
   GUICreate( "Run!", 270, 22, @DesktopWidth / 2 - 20, 0, $COMMONSTYLE, $COMMONSTYLEEX)
   
   $BUTTONSTYLE = $BS_CENTER + $BS_FLAT
   $CTR_OPEN = GUISetControl("button", '&Open...', 1, 1, 40, 19, $BUTTONSTYLE)
   
   $EDITSTYLE = $ES_WANTRETURN + $WS_VSCROLL + $WS_HSCROLL + $ES_AUTOVSCROLL + $ES_AUTOHSCROLL
   $CTR_INPUT = GUISetControl("input", $INPUT, 41, 1, 200, 20)
   GUISetControlEx($CTR_INPUT, $GUI_FOCUS + $GUI_ACCEPTFILES)
   
   $CTR_OK = GUISetControl("button", '&Run!', 241, 1, 28, 19, $BUTTONSTYLE)
   GUISetControlEx($CTR_OK, $GUI_DEFBUTTON)
   
   $CTR_VUP = GUISetControl("button", '&q', 23, 1, 10, 10, $BUTTONSTYLE)
   GUISetControlEx($CTR_VUP, $GUI_HIDE)
   $CTR_VDOWN = GUISetControl("button", '&a', 23, 1, 10, 10, $BUTTONSTYLE)
   GUISetControlEx($CTR_VDOWN, $GUI_HIDE)
   $CTR_VZERO = GUISetControl("button", '&z', 23, 1, 10, 10, $BUTTONSTYLE)
   GUISetControlEx($CTR_VZERO, $GUI_HIDE)
   
   GUIShow()
   GUIWaitClose()
   
   $INPUT = GUIRead($CTR_INPUT)
   Select;Understanding what key as been pressed.
      Case GUIRead() = $CTR_OK
         Select
            Case $INPUT = ''
              ;Nothing to do
            Case $INPUT = '!quit'    ;Exit program
               Exit
            Case $INPUT = '!help'    ;Open help file
               Run(@ComSpec & ' /c start "" "' & @ScriptDir & '\help.txt' & '"', '', @SW_HIDE)
            Case $INPUT = '!reboot'   ;Reboot
               Shutdown(2)
               Exit
            Case $INPUT = '!logoff'   ;Log off
               Shutdown(0)
               Exit
            Case $INPUT = '!shutdown' ;Turn off the computer
               Shutdown(8)
               Exit
            Case $INPUT = '!reboot!'  ;Forced reboot
               Shutdown(2 + 4)
               Exit
            Case $INPUT = '!shutdown!';Forced shutdown
               Shutdown(8 + 4)
               Exit
            Case Else
               Run(@ComSpec & ' /c start "" "' & $INPUT & '"', '', @SW_HIDE)
         EndSelect
      Case GUIRead() = $CTR_OPEN
         $INPUT = FileOpenDialog("Open a file...", "", "All (*.*)", 1)
         If @error = 1 Then $INPUT = ''
      Case GUIRead() = $CTR_VUP
         Send('{VOLUME_up}')
      Case GUIRead() = $CTR_VDOWN
         Send('{VOLUME_down}')
      Case GUIRead() = $CTR_VZERO
         Send('{VOLUME_mute}')
   EndSelect
   
   GUIDelete()
Wend


Exit
Func _SetConstants()
;The constant.au3 file with commented any constant I didnt used.
;removed for space.
EndFunc

I started playing with GUI only some days ago and I made this program that I already like.

But... When I use the ALT+Q/A/Z for managing volume I have to press again ALT anytime if I want to increase volume more than once. I possible allow the user just press ALT and keep pressed Q or A for a longer time and repeat the send command?

Also I'd like any kind of advice you can give me in order to make this more efficent, clean or what ever.

Thanks anyone. :ph34r:

Share this post


Link to post
Share on other sites



I have a new problem.

I'd like to implement a hotkey to popup the program, it should not be a problem a part that GUIWaitClose is a blocking function... How can I?

Share this post


Link to post
Share on other sites

I have a new problem.

I'd like to implement a hotkey to popup the program, it should not be a problem a part that GUIWaitClose is a blocking function... How can I?

<{POST_SNAPBACK}>

You need to use GUImsg() loop see advanced tutorial :ph34r:

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I replaced alot to make it work like you want it.

Edit:

CTRL+ALT+h is the hotkey to hide the command box and make it visible again.

Or you can enter the command !hide

And your first problem can't be solved. Because AutoIt doesn't know when a user is holding (for instance) the ALT key.

If WinExists('Ready to use command line.') Then ExitLoop
AutoItWinSetTitle('Ready to use command line.')



Opt ('TrayIconHide', 1)
Opt ('GUITaskbarEntry', 0)
Opt ('GUINotifyMode', 1)
_SetConstants()
Opt ('MustDeclareVars', 1)

Dim $COMMONSTYLE, $COMMONSTYLEEX, $EDITSTYLE, $BUTTONSTYLE;Styles related
Dim $INPUT = '', $CTR_INPUT                              ;Input related
Dim $CTR_OK, $CTR_OPEN, $CTR_VUP, $CTR_VDOWN, $CTR_VZERO    ;Buttons related
Global $Hidden, $Msg, $File

HotKeySet("^!h", "GuiVisible")

   $COMMONSTYLE = $WS_MINIMIZEBOX + $WS_GROUP + $WS_POPUP
   
   If IniRead('settings.ini', 'main', 'alwaysontop', 0) = 1 Then 
      $COMMONSTYLEEX = $WS_EX_TOPMOST + $WS_EX_ACCEPTFILES
   Else
      $COMMONSTYLEEX = $WS_EX_ACCEPTFILES
   EndIf
   GUICreate( "Run!", 270, 22, @DesktopWidth / 2 - 20, 0, $COMMONSTYLE, $COMMONSTYLEEX)
   
   $BUTTONSTYLE = $BS_CENTER + $BS_FLAT
   $CTR_OPEN = GUISetControl("button", '&Open...', 1, 1, 40, 19, $BUTTONSTYLE)
   
   $EDITSTYLE = $ES_WANTRETURN + $WS_VSCROLL + $WS_HSCROLL + $ES_AUTOVSCROLL + $ES_AUTOHSCROLL
   $CTR_INPUT = GUISetControl("input", $INPUT, 41, 1, 200, 20)
   GUISetControlEx($CTR_INPUT, $GUI_FOCUS + $GUI_ACCEPTFILES)
   
   $CTR_OK = GUISetControl("button", '&Run!', 241, 1, 28, 19, $BUTTONSTYLE)
   GUISetControlEx($CTR_OK, $GUI_DEFBUTTON)
   
   $CTR_VUP = GUISetControl("button", '&q', 23, 1, 10, 10, $BUTTONSTYLE)
   GUISetControlEx($CTR_VUP, $GUI_HIDE)
   $CTR_VDOWN = GUISetControl("button", '&a', 23, 1, 10, 10, $BUTTONSTYLE)
   GUISetControlEx($CTR_VDOWN, $GUI_HIDE)
   $CTR_VZERO = GUISetControl("button", '&z', 23, 1, 10, 10, $BUTTONSTYLE)
   GUISetControlEx($CTR_VZERO, $GUI_HIDE)
   
   GUIShow()
   
While 1
   Sleep(100)
   $Msg = GUIMsg(0)
   If $Msg = 0 Then ContinueLoop
   
   $INPUT = GUIRead($CTR_INPUT)
   Select;Understanding what key as been pressed.
      Case $Msg = $CTR_OK
         Select
            Case $INPUT = ''
            ;Nothing to do
            Case $INPUT = '!quit' OR $Msg = -3  ;Exit program
               ExitLoop
            Case $INPUT = '!help'    ;Open help file
               Run(@ComSpec & ' /c start "" "' & @ScriptDir & '\help.txt' & '"', '', @SW_HIDE)
            Case $INPUT = '!reboot'  ;Reboot
               Shutdown(2)
               ExitLoop
            Case $INPUT = '!logoff'  ;Log off
               Shutdown(0)
               ExitLoop
            Case $INPUT = '!shutdown';Turn off the computer
               Shutdown(8)
               ExitLoop
            Case $INPUT = '!reboot!';Forced reboot
               Shutdown(2 + 4)
               ExitLoop
            Case $INPUT = '!shutdown!';Forced shutdown
               Shutdown(8 + 4)
               ExitLoop
            Case $INPUT = '!hide'
                GuiVisible()
            Case Else
               Run(@ComSpec & ' /c start "" "' & $INPUT & '"', '', @SW_HIDE)
         EndSelect
      Case $Msg = $CTR_OPEN
         $File = FileOpenDialog("Open a file...", "", "All (*.*)", 1)
         If @error = 1 Then $File = ''
         GUIWrite($CTR_INPUT, 0, $File)
         
      Case $Msg = $CTR_VUP
         Send('{VOLUME_up}')
      Case $Msg = $CTR_VDOWN
         Send('{VOLUME_down}')
      Case $Msg = $CTR_VZERO
         Send('{VOLUME_mute}')
   EndSelect
   
Wend
HotKeySet("^!h")
GUIDelete()
Exit

Func GuiVisible()
    Select
        Case $Hidden = "Yes"
            $Hidden = "No"
            GUIShow()
        Case Else
            $Hidden = "Yes"
            GuiHide()
    EndSelect
EndFunc

Func _SetConstants()
;The constant.au3 file with commented any constant I didnt used.
;removed for space.
EndFunc
Edited by SlimShady

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks a lot. I'll see how do you!

EDIT: Understood... This use of ContinueLoop() is genial, thanks again... :ph34r:

Edited by ezzetabi

Share this post


Link to post
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
Sign in to follow this  
Followers 0