elite*gold: 0
Join Date: Feb 2008
Posts: 54
Received Thanks: 0
|
overlay counter need help
Weiter unten ein update und meine aktuelle version / updated version on the bottom
Hallo,
ich möchte im folgenden etwas mit autoit realisieren und hoffe auf hilfe und tipps von euch, da ich mich noch nicht so gut mit autoit auskenne.
durch einen hotkey soll ein timer aktiviert werden der von einer zuvor festgelegten sekundenanzahl (z.B. 300 sek) bis auf 0 sek runterzählt. der timer soll als overlay in einem spiel (an einer bestimmten position) angezeigt werden und wenn er ausgelaufen ist wieder verschwinden (eventuell auch mit einem kurzen sound beim ablauf des timers).
mein bisheriger code ist weiter unten
-----------------------------
hello,
i got a question for an autoit project i am working on. hope you guys can help me out, since i am not an autoit veteran 
how do i code this:
by clicking a hotkey a timer should visually appear on a game overlay counting down from e.g. 300 to 0, then disappear (maybe with an alert in the end). only a number should appear (no window).
sry for my bad english 
here is my code so far:
Code:
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
HotKeySet("{NUMPAD0}", "d")
HotKeySet("{NUMPAD9}", "On_Exit")
Global $TimeLabel, $_Seconds, $TimeTicks, $_SecCalc, $_Countdown, $SS_CENTER, $hGUI, $aRadio[5], $hButton, $res, $d_timer, $x_pos_d, $y_pos_d
$hGUI = GUICreate("LJT", 150, 190)
$x_pos_b = 100
$y_pos_b = 100
; gui to choose your in game resolution->
GUICtrlCreateLabel("Choose your resolution", 10, 10, 150, 20)
GUIStartGroup()
For $i = 0 To 4
Local $res[5] = ["2560 x 1440", "1920 x 1080", "1600 x 900", "1280 x 720", "1024 x 768"]
$aRadio[$i] = GUICtrlCreateRadio($res[$i], 55, 30 + ($i * 20), 100, 20)
Next
GUICtrlSetState($aRadio[0], $GUI_CHECKED)
$hButton = GUICtrlCreateButton("Start Timer", 35, 150, 80, 30)
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $hButton
GUISetState(@SW_HIDE, $hGUI)
For $i = 0 To 4
If GUICtrlRead($aRadio[$i]) = 1 Then
$res = $i
ExitLoop
EndIf
Next
Timer()
EndSwitch
WEnd
; gui timer on a non clickable overlay->
Func Timer()
Local $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
Local $hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, 0, 0)
$TimeLabel = GUICtrlCreateLabel ( "", $x_pos_b, $y_pos_b, 100, 50, $SS_CENTER )
GUICtrlSetFont ( -1, 8, 200 )
_WinAPI_SetWindowRgn($hRectangle_GUI, $hMaster_Mask)
GUISetState()
EndFunc
; countdown checkfunction calulates time in seconds and alerts @ 20 seconds / @ 1 second->
Func _Check ()
$_Countdown -= TimerDiff ( $TimeTicks )
$TimeTicks = TimerInit ( )
$_SecCalc = Int ( $_Countdown / 1000 )
If $_SecCalc <= 0 Then
GUICtrlSetData ( $TimeLabel, "" )
Else
If $_SecCalc <> $_Seconds Then
$_Seconds = $_SecCalc
GUICtrlSetData ( $TimeLabel, StringFormat ("%02u", $_Seconds ) )
If $_Seconds = 20 or $_Seconds = 1 Then
Beep ( 1200, 100 )
EndIf
EndIf
EndIf
EndFunc
; d function starts the countdown and sets the countdown time->
Func d()
$d_timer = 360000
$_Countdown = $d_timer
$TimeTicks = TimerInit ()
While 1
_Check()
Sleep (200)
WEnd
EndFunc
Func On_Exit()
Exit
EndFunc
UPDATE + updated code:
german:
nachdem in einer gui die bildschirmauflösung ausgewählt wurde, sollen auf knopfdruck in einem "durchklickbaren" und transparentem overlay Countdowntimer erstellt werden die von z.b. 300 sek bis 0 zählen und bei 20 sek und 1 sek einen warnton abgeben. Bei 0 sekunden soll der timer wieder verschwinden.
-> soweit funktioniert der code auch (unterschiedliche koordinaten je nach auflösung sind noch nicht vergeben worden, aber an dieser stelle erstmal auch nicht nötig)
Das problem: es können zwar alle 6 timer gestartet werden, aber visuell werden nur die änderungen von dem zuletzt geklickten timer angezeigt.
(-> anscheinend kann autoit funktionen in meinem skript nicht 6 mal parallel laufen lassen)
hat da jemand von euch eine elegante lösung?
auch generell andere anmerkungen/verbesserungsvorschläge zum code sind erwünscht
english:
The code works like this: you choose your resolution and press the "start" button. now a non clickable, transparent gui will appear. Countdowntimers will appear on the overlay by clicking different hotkeys.
what needs to be fixex:
if i press more than one hotkey, only the latest activated timer refreshes visually.
Code:
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
HotKeySet("{NUMPADDOT}", "b")
HotKeySet("{NUMPAD0}", "d")
HotKeySet("{NUMPAD1}", "o_b")
HotKeySet("{NUMPAD3}", "t_b")
HotKeySet("{NUMPAD4}", "o_r")
HotKeySet("{NUMPAD6}", "t_r")
HotKeySet("{NUMPAD9}", "On_Exit")
Global $SS_CENTER, $hGUI, $aRadio[5], $hButton, $res
Global $TimeLabel_d, $TimeLabel_b, $TimeLabel_ob, $TimeLabel_or, $TimeLabel_tb, $TimeLabel_tr, $TimeLabel
Global $TimeTicks_d, $TimeTicks_b, $TimeTicks_ob, $TimeTicks_or, $TimeTicks_tb, $TimeTicks_tr, $TimeTicks
Global $_SecCalc_d, $_SecCalc_b, $_SecCalc_ob, $_SecCalc_or, $_SecCalc_tb, $_SecCalc_tr, $_SecCalc
Global $_Seconds_d, $_Seconds_b, $_Seconds_ob, $_Seconds_or, $_Seconds_tb, $_Seconds_tr, $_Seconds
Global $x_pos_b, $y_pos_b, $x_pos_d, $y_pos_d, $x_pos_ob, $y_pos_ob, $x_pos_or, $y_pos_or, $x_pos_tb, $y_pos_tb, $x_pos_tr, $y_pos_tr
$hGUI = GUICreate("LJT", 150, 190)
$x_pos_d = 1825
$y_pos_d = 990
$x_pos_b = 1738
$y_pos_b = 884
$x_pos_ob = 1720
$y_pos_ob = 929
$x_pos_or = 1788
$y_pos_or = 996
$x_pos_tb = 1842
$y_pos_tb = 945
$x_pos_tr = 1772
$y_pos_tr = 877
GUICtrlCreateLabel("Choose your resolution", 10, 10, 150, 20)
GUIStartGroup()
For $i = 0 To 4
Local $res[5] = ["2560 x 1440", "1920 x 1080", "1600 x 900", "1280 x 720", "1024 x 768"]
$aRadio[$i] = GUICtrlCreateRadio($res[$i], 55, 30 + ($i * 20), 100, 20)
Next
GUICtrlSetState($aRadio[0], $GUI_CHECKED)
$hButton = GUICtrlCreateButton("Start Overlay", 35, 150, 80, 30)
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $hButton
GUISetState(@SW_HIDE, $hGUI)
For $i = 0 To 4
If GUICtrlRead($aRadio[$i]) = 1 Then
$res = $i
ExitLoop
EndIf
Next
Timer()
EndSwitch
WEnd
; -------------
Func Timer()
Local $hRectangle_GUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST + $WS_EX_LAYERED + $WS_EX_TRANSPARENT)
Local $hMaster_Mask = _WinAPI_CreateRectRgn(0, 0, @DesktopWidth, @DesktopHeight)
$TimeLabel_d = GUICtrlCreateLabel ( "", $x_pos_d, $y_pos_d, 20, 15, $SS_CENTER )
$TimeLabel_b = GUICtrlCreateLabel ( "", $x_pos_b, $y_pos_b, 20, 15, $SS_CENTER )
$TimeLabel_ob = GUICtrlCreateLabel ( "", $x_pos_ob, $y_pos_ob, 20, 15, $SS_CENTER )
$TimeLabel_or = GUICtrlCreateLabel ( "", $x_pos_or, $y_pos_or, 20, 15, $SS_CENTER )
$TimeLabel_tb = GUICtrlCreateLabel ( "", $x_pos_tb, $y_pos_tb, 20, 15, $SS_CENTER )
$TimeLabel_tr = GUICtrlCreateLabel ( "", $x_pos_tr, $y_pos_tr, 20, 15, $SS_CENTER )
GUISetFont ( -1, 8, 200 )
GuiCtrlSetColor($TimeLabel_d, 0xFF00FF)
GuiCtrlSetColor($TimeLabel_b, 0xFF00FF)
GuiCtrlSetColor($TimeLabel_ob, 0x0000FF)
GuiCtrlSetColor($TimeLabel_or, 0xFF0000)
GuiCtrlSetColor($TimeLabel_tb, 0x0000FF)
GuiCtrlSetColor($TimeLabel_tr, 0xFF0000)
GUISetBkColor(0xABCDEF)
_WinAPI_SetLayeredWindowAttributes($hRectangle_GUI, 0xABCDEF, 255)
GUISetState()
EndFunc
Func _Check ($timer, $TimeTicks, $TimeLabel, $_SecCalc, $_Seconds)
$timer -= TimerDiff ( $TimeTicks )
$TimeTicks = TimerInit ( )
$_SecCalc = Int ( $timer / 1000 )
If $_SecCalc <= 0 Then
GUICtrlSetData ( $TimeLabel, "" )
Else
If $_SecCalc <> $_Seconds Then
$_Seconds = $_SecCalc
GUICtrlSetData ( $TimeLabel, StringFormat ("%02u", $_Seconds ) )
If $_Seconds = 20 or $_Seconds = 1 Then
Beep ( 1200, 100 )
EndIf
EndIf
EndIf
EndFunc
Func d()
$d_timer = 360000
$TimeTicks_d = TimerInit ()
While 1
_Check($d_timer, $TimeTicks_d, $TimeLabel_d, $_SecCalc_d, $_Seconds_d)
Sleep (200)
WEnd
EndFunc
Func b()
$b_timer = 420000
$TimeTicks_b = TimerInit ()
While 1
_Check($b_timer, $TimeTicks_b, $TimeLabel_b, $_SecCalc_b, $_Seconds_b)
Sleep (200)
WEnd
EndFunc
Func o_b()
$ob_timer = 300000
$TimeTicks_ob = TimerInit ()
While 1
_Check($ob_timer, $TimeTicks_ob, $TimeLabel_ob, $_SecCalc_ob, $_Seconds_ob)
Sleep (200)
WEnd
EndFunc
Func o_r()
$or_timer = 300000
$TimeTicks_or = TimerInit ()
While 1
_Check($or_timer, $TimeTicks_or, $TimeLabel_or, $_SecCalc_or, $_Seconds_or)
Sleep (200)
WEnd
EndFunc
Func t_b()
$tb_timer = 300000
$TimeTicks_tb = TimerInit ()
While 1
_Check($tb_timer, $TimeTicks_tb, $TimeLabel_tb, $_SecCalc_tb, $_Seconds_tb)
Sleep (200)
WEnd
EndFunc
Func t_r()
$tr_timer = 300000
$TimeTicks_tr = TimerInit ()
While 1
_Check($tr_timer, $TimeTicks_tr, $TimeLabel_tr, $_SecCalc_tr, $_Seconds_tr)
Sleep (200)
WEnd
EndFunc
Func On_Exit()
Exit
EndFunc
|