Hilfe bei hotkey und button funktion

05/21/2020 17:03 staRRFreak#1
Hallo kann mir jemand helfen und mir vielleicht sagen wieso mein Script nicht funktioniert weder die Hotkeys noch die Buttons funktionieren


Code:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=c:\users\user\desktop\form1.kxf
$Form1_1 = GUICreate("TEST TEXT", 220, 309, 316, 243)
$startb = GUICtrlCreateButton("Start", 40, 16, 139, 49)
GUICtrlSetOnEvent($startb,"_start")
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$stopb = GUICtrlCreateButton("Stop", 40, 80, 139, 49)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$exitb = GUICtrlCreateButton("Kill ME!", 40, 144, 139, 49)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("TEXT", 40, 208, 155, 17)
$Label2 = GUICtrlCreateLabel("TEXT", 40, 224, 79, 17)
$Label3 = GUICtrlCreateLabel("Up - Start", 40, 240, 47, 17)
$Label4 = GUICtrlCreateLabel("Down - Stop", 40, 256, 47, 17)
$Label5 = GUICtrlCreateLabel("ESC - Exit", 40, 272, 51, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit

		 Case $exitb
			Exit

		 Case $startb
			_start()

		 Case $stopb
			_pause()

	EndSwitch
 WEnd

While 1
   sleep(100)
WEnd

HotKeySet("{UP}","_start")
HotKeySet("{DOWN}","_pause")
HotKeySet("{ESC}","Exit")

Global $go = 0

While 1
   if $go = 0 Then
		 Sleep (100)
   Else
	  _move()
   EndIf
WEnd

Func _start()
   $go = 1
EndFunc

Func _pause()
   $go = 0
EndFunc

Func _move()
   While 1
	  MouseMove( 300, 300)
		 Sleep(2500)
	  MouseMove( 600, 300)
		 Sleep(2500)
   WEnd
EndFunc
05/21/2020 17:07 SyntaxBreaker#2
Der Code zum setzen wird nie erreicht.
While 1
sleep(100)
Wend

ist eine Endlosschleife
05/21/2020 18:27 staRRFreak#3
Quote:
Originally Posted by SyntaxBreaker View Post
Der Code zum setzen wird nie erreicht.
While 1
sleep(100)
Wend

ist eine Endlosschleife
auch ohne die schleife funktioniert es nicht da stimmt was mit der GUI nicht
sobald ich die gui entferne funktioniert es

oder
wen ich die Buttons in der GUI die Funktion umschreibe von

Code:
While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit

		 Case $exitb
			_exit()

		 Case $startb
			_start()

		 Case $pauseb
			_pause()

	EndSwitch
 WEnd
Auf

Code:
While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit

		 Case $exitb
			_exit()

		 Case $startb
			_move() ;so Startet es 

		 Case $pauseb
			_pause()  ;funktioniert gar nicht while 1 sleep(100) wend bringt keine Änderung Auch ohne GUI keine Funktion

	EndSwitch
 WEnd
irgendwie wird Global $go = 0 nicht auf 1 gestellt oder es wird gestellt aber die funktion _move() wird nicht aktiviert
05/22/2020 05:08 elmarcia#4
Sir let me explain what a while loop is because i think you forgot.

[Only registered and activated users can see links. Click Here To Register...]

So that means that while loops are bad and shouldn't be used?, of course not, but that is not the way that they should be used.

You can achive same result with only one loop and a bunch of ifs.

If you want your code more readable, then divide and conquer (split functionality in simple functions and call them inside your loop)

Lets forget about the gui for now

Ex:
[Only registered and activated users can see links. Click Here To Register...]

But what about the gui, well... you can easily put it all together in one loop


Just give me the f****** code
[Only registered and activated users can see links. Click Here To Register...]

And here is the final result:


Edit: i messed up with the second image should be false on _pause, fixed in code anyway