Opened 13 years ago

Closed 13 years ago

#1862 closed Feature Request (Rejected)

GUISetOnEvent should behave more like HotKeySet()

Reported by: anonymous Owned by:
Milestone: Component: AutoIt
Version: Severity: None
Keywords: hotkeypress guisetonevent loop Cc:


What I mean is this little snippet from the help file for HotKeySet:

A hotkey-press *typically* interrupts the active AutoIt function/statement and runs its user function until it completes or is interrupted. Exceptions are as follows:
1) If the current function is a "blocking" function, then the key-presses are buffered and execute as soon as the blocking function completes. MsgBox and FileSelectFolder are examples of blocking functions. Try the behavior of Shift-Alt-d in the Example.
2) If you have paused the script by clicking on the AutoIt Tray icon, any hotkeys pressed during this paused state are ignored.

What I get out of this If the script is processing 'loop' than a GUISetOnEvent user function is treated *always* as blocking so it is buffered and called after the 'loop' finishes (which in case of our example, it will take a long time) If we press a hotkey then that user function is checked if it is blocking, if it is not blocking than it is called right away.

I believe GUISetOnEvent should behave more like HotKeySet() in this regard.

Messy messy example

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

Global $iOperationRun = False

$hMain = GUICreate("Example", 170, 153, 231, 205)
$gcProgressMain = GUICtrlCreateProgress(8, 8, 150, 16)
$gcProgressSub1 = GUICtrlCreateProgress(8, 24, 150, 16)
$gcProgressSub2 = GUICtrlCreateProgress(8, 40, 150, 16)
$gcProgressText = GUICtrlCreateLabel("Ready", 8, 64, 150, 17)
$gcStartStop = GUICtrlCreateButton("Start", 40, 88, 75, 25, $WS_GROUP)
GUICtrlSetTip($gcStartStop, "Press me, if you dare")
$gcExit = GUICtrlCreateButton("Exit", 40, 120, 75, 25, $WS_GROUP)

Opt("GUIOnEventMode", 1)

HotKeySet("{esc}", "Quit")
GUICtrlSetOnEvent($gcExit, "Quit")

HotKeySet("{f1}", "HotKeyEvent")
GUICtrlSetOnEvent($gcStartStop, "ButtonPressEvent")

HotKeySet("{F2}", "I_Will_NOT_Interupt")
HotKeySet("{F3}", "I_WILL_Interupt")
Func I_Will_NOT_Interupt()
	ConsoleWrite("{f2} I will politely say that you pressed me" &@lf)
Func I_WILL_Interupt()
	While 1
		If $iOperationRun = False Then ExitLoop
		ConsoleWrite("How rude!, All your cpu cycles are belong to me" &@lf)

While 1

Func HotKeyEvent()
	If WinActive($hMain) Then OperationManager()

Func ButtonPressEvent()

Func OperationManager()
	If $iOperationRun = True Then
		GUICtrlSetData($gcProgressText, "Stopped")
		GUICtrlSetData($gcStartStop, "Start")
		GUICtrlSetTip($gcStartStop, "Press me, if you dare")
		$iOperationRun = False
		GUICtrlSetData($gcProgressText, "Doing stuff..")
		GUICtrlSetData($gcStartStop, "Stop")
		GUICtrlSetTip($gcStartStop, "I can't be stopped!! unless you press F1, or ESC ;)")
		GUICtrlSetTip($gcExit, "I can't be stopped!! unless you press F1, or ESC ;)")
		$iOperationRun = True

Func Quit()

Func ProgressLoop()
	Local $myCount = 0

	For $x = 1 To 10
		GUICtrlSetData($gcProgressMain, ($x / 10 * 100))
		For $y = 1 To 40
			If $iOperationRun = False Then ExitLoop 2  ;try to quit as soon as possible


			$myCount += 1  ; this value stays the same even when nonInterupting() is called, interesting.

			GUICtrlSetData($gcProgressSub1, ($y / 40 * 100))

			ConsoleWrite( $myCount &@lf)

			For $z = 1 To 80

				GUICtrlSetData($gcProgressSub2, ($z / 80 * 100))
				If $iOperationRun = False Then ExitLoop 3  ;try to quit as soon as possible


			If $iOperationRun = False  Then ExitLoop 2 ;try to quit as soon as possible

		If $iOperationRun = False  Then ExitLoop ;try to quit as soon as possible


Attachments (0)

Change History (2)

comment:1 Changed 13 years ago by TicketCleanup

  • Version deleted

Automatic ticket cleanup.

comment:2 Changed 13 years ago by Valik

  • Resolution set to Rejected
  • Status changed from new to closed

Receiving a second GUI message before handling of the first message is complete can be disastrous. You should never execute long-running tasks in a GUI callback function no matter what language. It's poor application design.

Closing as rejected.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

as closed The ticket will remain with no owner.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.