Jump to content

GUIOnEventMode help needed, only 1 button seems to work


Kovacic
 Share

Recommended Posts

Semi experienced developer here.. I have never fully gotten the handle of using GUIOnEventMode, so i thought I would try it with a small simple program that I can paste some text into, then have it count down, and type it out for me.. I use this for when I am iLO into a server and I cant paste. For those of you not familiar with iLO, it stands for Integrated Lights Out. in short, it lets you remote into a server even if its having BIOS issue and wont start.. more details here: http://www8.hp.com/us/en/products/servers/ilo/

 

Anyway, when in iLO, you cant paste anything. Sometimes I need to copy bash scripting from my computer to the server, so I drop it in the little app, then use it to type out the script in the iLO screen. I have it so it does a countdown before sending the keys, and a delay between each key ( because iLO will sometimes hang up a little ). 

 

The app I am trying to write will count down, then send whatever is in the edit box. I also have a stop button in case you want to stop the app, but that doesn't seem to do anything. I feel like I'm using GUIOnEventMode improperly. Can someone take a peek?

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
;Opt                                     ("GUICoordMode", 2)
Opt                                      ("GUIResizeMode", 1)
Opt                                      ("GUIOnEventMode", 1)
GUISetOnEvent                            ($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent                            ($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent                            ($GUI_EVENT_RESTORE, "SpecialEvents")
$Form1 = GUICreate                       ("Sender", 615, 438, 192, 124)
$edit = GUICtrlCreateEdit                ("", 8, 128, 601, 305)
$stop = GUICtrlCreateButton              ("STOP", 496, 60, 100, 25)
GUICtrlSetOnEvent                        (-1, "stop")
$SEND = GUICtrlCreateButton              ("SEND", 496, 88, 100, 25)
GUICtrlSetOnEvent                        (-1, "sendit")
$SecsToWaitB4Sending = GUICtrlCreateInput("10", 200, 32, 145, 25)
GUICtrlCreateLabel                       ("Seconds to wait before sending", 40, 32, 153, 17)
GUICtrlCreateLabel                       ("Delay between char sent in ms.", 40, 64, 152, 17)
$MSBetweenLEtters = GUICtrlCreateInput   ("100", 200, 64, 145, 25)
GUISetState                              (@SW_SHOW)
While 1
    Sleep(5)
WEnd
Func stop()
    GUICtrlSetData($SEND, "SEND")
EndFunc   ;==>stop
Func sendit()
    Local $h = Int(GUICtrlRead($SecsToWaitB4Sending))
    GUICtrlSetData($SEND, "Waiting")
    For $i = 1 To Int(GUICtrlRead($SecsToWaitB4Sending))
        GUICtrlSetData($SEND, $h)
        For $c = 1 To 100
            Sleep(1)
        Next
        $h -= 1
    Next
    GUICtrlSetData($SEND, "Typing")
    Opt("SendKeyDelay", Int(GUICtrlRead($MSBetweenLEtters)))
    Send(GUICtrlRead($edit), 1)
    GUICtrlSetData($SEND, "SEND")
EndFunc   ;==>sendit
Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Exit
        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
            ;
        Case @GUI_CtrlId = $GUI_EVENT_RESTORE
            ;
    EndSelect
EndFunc   ;==>SpecialEvents

 

 

 

Thanks in advance!

 

 

Edited by Kovacic

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

I would solve the problem with AdlibRegister:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
;Opt                                     ("GUICoordMode", 2)
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)
Global $h
$Form1 = GUICreate("Sender", 615, 438, 192, 124)
$edit = GUICtrlCreateEdit("", 8, 128, 601, 305)
$stop = GUICtrlCreateButton("STOP", 496, 60, 100, 25)
GUICtrlSetOnEvent(-1, "stopSend")
$SEND = GUICtrlCreateButton("SEND", 496, 88, 100, 25)
GUICtrlSetOnEvent(-1, "startSend")
$SecsToWaitB4Sending = GUICtrlCreateInput("10", 200, 32, 145, 25)
GUICtrlCreateLabel("Seconds to wait before sending", 40, 32, 153, 17)
GUICtrlCreateLabel("Delay between char sent in ms.", 40, 64, 152, 17)
$MSBetweenLEtters = GUICtrlCreateInput("100", 200, 64, 145, 25)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") ;funktioniert frühestens nach GuiCreate
;GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")    ;unnötig wenn Standardaktion
;GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")     ;unnötig wenn Standardaktion
$receiver=GUICreate('Empfänger')
GUICtrlCreateEdit('',5,5,200,200)
GUISetState(@SW_HIDE)
GUICtrlSetData($edit,'--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop'&@CRLF)
;zum Verständnis kann nach Test entfernt werden
While 1
    Sleep(500)
WEnd

Func stopSend()
    AdlibUnRegister('sendit') ;beendet den Aufruf der Func sendit
    GUICtrlSetData($SEND, "SEND")
    ConsoleWrite('Abbruch durch Benutzer' & @CRLF) ;kann entfernt werden
EndFunc   ;==>stopSend

Func startSend()
    Opt("SendKeyDelay", Int(GUICtrlRead($MSBetweenLEtters)))
    $h = Int(GUICtrlRead($SecsToWaitB4Sending))
    GUICtrlSetData($SEND, "Waiting")
    AdlibRegister('sendit', 1000) ;registriert die Func sendit und ruft sie alle 1000 ms auf
    sendit() ;damit sendit sofort und nicht erst nach 1000 ms aufgerufen wird
EndFunc   ;==>startSend

Func sendit()
    $toSend = GUICtrlRead($edit)
    $aToSend = StringSplit($toSend,'')
    If $h = 0 Then
        GUISetState(@SW_SHOW,$receiver) ;kann entfernt werden
        WinActivate($receiver)          ;kann entfernt werden
        $iStart = TimerInit()
        Send($toSend, 1)
        ConsoleWrite('String: '&TimerDiff($iStart)&@CRLF)
        ;diese Schleife zum Verständnis mindestens 1 mal testen
        ;danach kann sie entfernt werden
        $iStart = TimerInit()
        For $i = 1 To $aToSend[0]
            Send($aToSend[$i],1)
        Next
        ConsoleWrite("Char's: "&TimerDiff($iStart)&@CRLF)
        ;Unterschied bemerkt???
        Sleep(2500)                     ;kann entfernt werden
        GUISetState(@SW_HIDE,$receiver) ;kann entfernt werden
        ConsoleWrite($toSend & @CRLF & 'wurde gesendet' & @CRLF) ;kann entfernt werden
        GUICtrlSetData($SEND, "SEND")
        AdlibUnRegister('sendit') ;beendet den Aufruf der Func sendit
    Else
        GUICtrlSetData($SEND, $h)
        $h -= 1
    EndIf
EndFunc   ;==>sendit

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Exit
        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
            ;
        Case @GUI_CtrlId = $GUI_EVENT_RESTORE
            ;
    EndSelect
EndFunc   ;==>SpecialEvents

 

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

×
×
  • Create New...