RichE Posted August 20, 2009 Share Posted August 20, 2009 (edited) I play guildwars and one of the most annoying thing is that one of your skills times out as your busy, so I modified the progressbar example, but to active when the relevant skill key is pressed, in guildwars (if you haven't played it) you have uto 8 skills 18 number keys, but when I press say 1, it locks the gui and won't accept any more key presses until the progress bar for skill1 has got to 0, when I'm playing I want this to sit at the side of my window and monitor the 1-8 number keys thats it, and start the count down when the corresponding key is pressed, could some one point out where I've gone wrong..? expandcollapse popup#include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <misc.au3> ;Opt('MustDeclareVars', 1) Local $progressbar1, $progressbar2, $progressbar3, $progressbar4 ,$progressbar5 ,$progressbar6,$progressbar7,$progressbar8 ,$wait, $s, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $msg, $dll $dll = DllOpen("user32.dll") GUICreate("Skill timer", 320, 280, -1,-1) GUICtrlCreateLabel("Skill 1", 10, 15, 70, 20) $progressbar1 = GUICtrlCreateProgress(60, 10, 200, 20, $PBS_SMOOTH) $t1 = guictrlcreatelabel("60", 270, 15, 40, 20) $e1 = guictrlcreatebutton("e", 295, 10, 20, 20) GUICtrlCreateLabel("Skill 2", 10, 45, 70, 20) $progressbar2 = GUICtrlCreateProgress(60, 40, 200, 20, $PBS_SMOOTH) $t2 = guictrlcreatelabel("60", 270, 45, 40, 20) $e2 = guictrlcreatebutton("e", 295, 40, 20, 20) GUICtrlCreateLabel("Skill 3", 10, 75, 70, 20) $progressbar3 = GUICtrlCreateProgress(60, 70, 200, 20, $PBS_SMOOTH) $t3 = guictrlcreatelabel("60", 270, 75, 40, 20) $e3 = guictrlcreatebutton("e", 295, 70, 20, 20) GUICtrlCreateLabel("Skill 4", 10, 105, 70, 20) $progressbar4 = GUICtrlCreateProgress(60, 100, 200, 20, $PBS_SMOOTH) $t4 = guictrlcreatelabel("60", 270, 105, 40, 20) $e4 = guictrlcreatebutton("e", 295, 100, 20, 20) GUICtrlCreateLabel("Skill 5", 10, 135, 70, 20) $progressbar5 = GUICtrlCreateProgress(60, 130, 200, 20, $PBS_SMOOTH) $t5 = guictrlcreatelabel("60", 270, 135, 40, 20) $e5 = guictrlcreatebutton("e", 295, 130, 20, 20) GUICtrlCreateLabel("Skill 6", 10, 165, 70, 20) $progressbar6 = GUICtrlCreateProgress(60, 160, 200, 20, $PBS_SMOOTH) $t6 = guictrlcreatelabel("60", 270, 165, 40, 20) $e6 = guictrlcreatebutton("e", 295, 160, 20, 20) GUICtrlCreateLabel("Skill 7", 10, 195, 70, 20) $progressbar7 = GUICtrlCreateProgress(60, 190, 200, 20, $PBS_SMOOTH) $t7 = guictrlcreatelabel("60", 270, 195, 40, 20) $e7 = guictrlcreatebutton("e", 295, 190, 20, 20) GUICtrlCreateLabel("Skill 8", 10, 225, 70, 20) $progressbar8 = GUICtrlCreateProgress(60, 220, 200, 20, $PBS_SMOOTH) $t8 = guictrlcreatelabel("60", 270, 225, 40, 20) $e8 = guictrlcreatebutton("e", 295, 220, 20, 20) GUISetState() $wait = 800 $s = 0 guictrlsetdata($progressbar1, guictrlread($t1)) guictrlsetdata($progressbar2, guictrlread($t2)) guictrlsetdata($progressbar3, guictrlread($t3)) guictrlsetdata($progressbar4, guictrlread($t4)) guictrlsetdata($progressbar5, guictrlread($t5)) guictrlsetdata($progressbar6, guictrlread($t6)) guictrlsetdata($progressbar7, guictrlread($t7)) guictrlsetdata($progressbar8, guictrlread($t8)) while 1 $msg = GUIGetMsg() switch $msg case $msg = _IsPressed(31, $DLL) For $i = $s To guictrlread($t1) $s = 0 GUICtrlSetData($progressbar1, (guictrlread($t1) - $i)) Sleep($wait) Next guictrlsetdata($progressbar1, guictrlread($t1)) case $msg = _IsPressed(32, $DLL) For $i = $s To guictrlread($t2) $s = 0 GUICtrlSetData($progressbar2, (guictrlread($t2) - $i)) Sleep($wait) Next guictrlsetdata($progressbar2, guictrlread($t2)) case $msg = _IsPressed(33, $DLL) For $i = $s To guictrlread($t3) $s = 0 GUICtrlSetData($progressbar3, (guictrlread($t3) - $i)) Sleep($wait) Next guictrlsetdata($progressbar3, guictrlread($t3)) case $msg = _IsPressed(34, $DLL) For $i = $s To guictrlread($t4) $s = 0 GUICtrlSetData($progressbar4, (guictrlread($t4) - $i)) Sleep($wait) Next guictrlsetdata($progressbar4, guictrlread($t4)) case $msg = _IsPressed(35, $DLL) For $i = $s To guictrlread($t5) $s = 0 GUICtrlSetData($progressbar5, (guictrlread($t5) - $i)) Sleep($wait) Next guictrlsetdata($progressbar5, guictrlread($t5)) case $msg = _IsPressed(36, $DLL) For $i = $s To guictrlread($t6) $s = 0 GUICtrlSetData($progressbar6, (guictrlread($t6) - $i)) Sleep($wait) Next guictrlsetdata($progressbar6, guictrlread($t6)) case $msg = _IsPressed(37, $DLL) For $i = $s To guictrlread($t7) $s = 0 GUICtrlSetData($progressbar7, (guictrlread($t7) - $i)) Sleep($wait) Next guictrlsetdata($progressbar7, guictrlread($t7)) case $msg = _IsPressed(38, $DLL) For $i = $s To guictrlread($t8) $s = 0 GUICtrlSetData($progressbar8, (guictrlread($t8) - $i)) Sleep($wait) Next guictrlsetdata($progressbar8, guictrlread($t8)) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd thanks in advanceGWS_timer.au3 Edited August 20, 2009 by l15ard RichE [font="'Arial Narrow';"]Current projects[/font] [font="'Arial Narrow';"]are on my site [/font]Sellostring Link to comment Share on other sites More sharing options...
smashly Posted August 21, 2009 Share Posted August 21, 2009 (edited) Hi, Your stuck in a loop while updating the progress bar so no other keypress will work until that loop is finised.. I had a play with your code, but I don't think your going to like my butcher job ..lol But you can have multiple progress bars going and exit the Gui straight away, wasn't sure what the e buttons were for.expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <StructureConstants.au3> #include <ProgressConstants.au3> Opt('MustDeclareVars', 1) ; $Start is how full the progess bar starts at value of 1 To 100 ; $Wait is how many millisecons to wait before the progress bar steps down a notch Global $Start = 60, $Wait = 800 Global $hGui, $aProgress[8][2], $aT[8], $aE[8], $msg Global $hStub_KeyProc, $hHook $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam") $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), _WinAPI_GetModuleHandle(0)) $hGui = GUICreate("Skill timer", 320, 280, -1, -1, -1, $WS_EX_TOPMOST) For $i = 0 To UBound($aProgress, 1) - 1 GUICtrlCreateLabel("Skill " & $i + 1, 10, ($i * 30) + 15, 70, 20) $aProgress[$i][0] = GUICtrlCreateProgress(60, ($i * 30) + 10, 200, 20, $PBS_SMOOTH) GUICtrlSetData(-1, $Start) $aT[$i] = GUICtrlCreateLabel($Start, 270, ($i * 30) + 15, 30, 20) $aE[$i] = GUICtrlCreateButton("e", 295, ($i * 30) + 10, 20, 20) Next GUISetState(@SW_SHOW, $hGui) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $aE[0] ;; 1st Button has been pressed do something Case $aE[1] ;; 2nd Button has been pressed do something Case $aE[2] ;; 3rd Button has been pressed do something Case $aE[3] ;; 4th Button has been pressed do something Case $aE[4] ;; 5th Button has been pressed do something Case $aE[5] ;; 6th Button has been pressed do something Case $aE[6] ;; 7th Button has been pressed do something Case $aE[7] ;; 8th Button has been pressed do something Case Else _Timer() EndSwitch WEnd Func _Timer() For $i = 0 To UBound($aProgress, 1) - 1 If $aProgress[$i][1] Then If TimerDiff($aProgress[$i][1]) >= $Wait And GUICtrlRead($aProgress[$i][0]) > 0 Then GUICtrlSetData($aProgress[$i][0], GUICtrlRead($aProgress[$i][0]) - (TimerDiff($aProgress[$i][1]) / $Wait)) GUICtrlSetData($aT[$i], GUICtrlRead($aProgress[$i][0])) $aProgress[$i][1] = TimerInit() ElseIf GUICtrlRead($aProgress[$i][0]) <= 0 Then GUICtrlSetData($aProgress[$i][0], $Start) GUICtrlSetData($aT[$i], $Start) $aProgress[$i][1] = 0 EndIf EndIf Next EndFunc ;==>_Timer Func _KeyProc($nCode, $wParam, $lParam) Local $tKEYHOOKS, $iVK $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) If $wParam = $WM_KEYDOWN Then $iVK = DllStructGetData($tKEYHOOKS, "vkCode") Switch $iVK Case 49 To 56 If Not $aProgress[Chr($iVK - 1)][1] Then $aProgress[Chr($iVK - 1)][1] = TimerInit() EndSwitch EndIf Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc ;==>_KeyProc Func OnAutoItExit() _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hStub_KeyProc) EndFunc ;==>OnAutoItExitCheers Edited August 21, 2009 by smashly Link to comment Share on other sites More sharing options...
RichE Posted August 21, 2009 Author Share Posted August 21, 2009 (edited) Hi, Your stuck in a loop while updating the progress bar so no other keypress will work until that loop is finised.. I had a play with your code, but I don't think your going to like my butcher job ..lol But you can have multiple progress bars going and exit the Gui straight away, wasn't sure what the e buttons were for.expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <StructureConstants.au3> #include <ProgressConstants.au3> Opt('MustDeclareVars', 1) ; $Start is how full the progess bar starts at value of 1 To 100 ; $Wait is how many millisecons to wait before the progress bar steps down a notch Global $Start = 60, $Wait = 800 Global $hGui, $aProgress[8][2], $aT[8], $aE[8], $msg Global $hStub_KeyProc, $hHook $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam") $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), _WinAPI_GetModuleHandle(0)) $hGui = GUICreate("Skill timer", 320, 280, -1, -1, -1, $WS_EX_TOPMOST) For $i = 0 To UBound($aProgress, 1) - 1 GUICtrlCreateLabel("Skill " & $i + 1, 10, ($i * 30) + 15, 70, 20) $aProgress[$i][0] = GUICtrlCreateProgress(60, ($i * 30) + 10, 200, 20, $PBS_SMOOTH) GUICtrlSetData(-1, $Start) $aT[$i] = GUICtrlCreateLabel($Start, 270, ($i * 30) + 15, 30, 20) $aE[$i] = GUICtrlCreateButton("e", 295, ($i * 30) + 10, 20, 20) Next GUISetState(@SW_SHOW, $hGui) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $aE[0] ;; 1st Button has been pressed do something Case $aE[1] ;; 2nd Button has been pressed do something Case $aE[2] ;; 3rd Button has been pressed do something Case $aE[3] ;; 4th Button has been pressed do something Case $aE[4] ;; 5th Button has been pressed do something Case $aE[5] ;; 6th Button has been pressed do something Case $aE[6] ;; 7th Button has been pressed do something Case $aE[7] ;; 8th Button has been pressed do something Case Else _Timer() EndSwitch WEnd Func _Timer() For $i = 0 To UBound($aProgress, 1) - 1 If $aProgress[$i][1] Then If TimerDiff($aProgress[$i][1]) >= $Wait And GUICtrlRead($aProgress[$i][0]) > 0 Then GUICtrlSetData($aProgress[$i][0], GUICtrlRead($aProgress[$i][0]) - (TimerDiff($aProgress[$i][1]) / $Wait)) GUICtrlSetData($aT[$i], GUICtrlRead($aProgress[$i][0])) $aProgress[$i][1] = TimerInit() ElseIf GUICtrlRead($aProgress[$i][0]) <= 0 Then GUICtrlSetData($aProgress[$i][0], $Start) GUICtrlSetData($aT[$i], $Start) $aProgress[$i][1] = 0 EndIf EndIf Next EndFunc ;==>_Timer Func _KeyProc($nCode, $wParam, $lParam) Local $tKEYHOOKS, $iVK $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) If $wParam = $WM_KEYDOWN Then $iVK = DllStructGetData($tKEYHOOKS, "vkCode") Switch $iVK Case 49 To 56 If Not $aProgress[Chr($iVK - 1)][1] Then $aProgress[Chr($iVK - 1)][1] = TimerInit() EndSwitch EndIf Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc ;==>_KeyProc Func OnAutoItExit() _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hStub_KeyProc) EndFunc ;==>OnAutoItExitCheers that works exactly as I wanted it to, thanks for the help, now I just have to get my head around the code you wrote, the e button is to edit the amount of time per skill, as you can see their all set to 60 atm Edited August 21, 2009 by l15ard RichE [font="'Arial Narrow';"]Current projects[/font] [font="'Arial Narrow';"]are on my site [/font]Sellostring Link to comment Share on other sites More sharing options...
smashly Posted August 22, 2009 Share Posted August 22, 2009 (edited) that works exactly as I wanted it to, thanks for the help, now I just have to get my head around the code you wrote, the e button is to edit the amount of time per skill, as you can see their all set to 60 atm Your welcome, Had a further play with your code (I was bored.. lol) Added Edit timer functions and an Edit all timers button (the times are base as seconds). Added Stop timer buttons, also added a Stop all timers button (Basically it stops and resets the timer or timers) Progress Bar always start as a Full bar, just the Label tells how many seconds the timer is set for or left to go. Added Start/Stop Monitoring keys button. Added Save/load X & Y Gui position and Timer values (Saves on exit, Loads on start of Gui) So if you had trouble wrapping your mind on my non commented butchered efforts before, then it's even worse now.. lolexpandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> Opt('MustDeclareVars', 1) Global $Ini = @ScriptDir & "\SkillTimer.ini", $iWait = 1000 Global $hGui, $aXY[2], $aProgress[8][2], $aStart[8], $aT[8][2], $aE[8], $aS[8], $Eall, $Sall, $Skey, $msg Global $hStub_KeyProc, $hHook _Load() $hGui = GUICreate("Skill timer", 295, 280, $aXY[0], $aXY[1], -1, $WS_EX_TOPMOST) For $i = 0 To UBound($aProgress, 1) - 1 GUICtrlCreateLabel("Skill " & $i + 1, 10, ($i * 30) + 10, 35, 20, BitOR($SS_CENTER, $BS_CENTER)) $aProgress[$i][0] = GUICtrlCreateProgress(50, ($i * 30) + 10, 150, 20, $PBS_SMOOTH) GUICtrlSetData(-1, 100) $aT[$i][0] = GUICtrlCreateLabel($aStart[$i], 205, ($i * 30) + 10, 30, 20, BitOR($SS_CENTER, $BS_CENTER)) $aE[$i] = GUICtrlCreateButton("E", 240, ($i * 30) + 10, 20, 20) GUICtrlSetTip(-1, "Click E button to edit the timer for skill " & $i + 1) $aS[$i] = GUICtrlCreateButton("S", 265, ($i * 30) + 10, 20, 20) GUICtrlSetTip(-1, "Click S button to stop the timer for skill " & $i + 1) Next $Skey = GUICtrlCreateButton("Start Key Monitoring", 10, ($i * 30) + 10, 105, 20) $Eall = GUICtrlCreateButton("Edit all timers", 125, ($i * 30) + 10, 75, 20) $Sall = GUICtrlCreateButton("Stop all timers", 210, ($i * 30) + 10, 75, 20) GUISetState(@SW_SHOW, $hGui) _ToggleKeyHook() GUIRegisterMsg($WM_MOVE, "WM_MOVE") While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE _Save() Exit Case $aE[0], $aE[1], $aE[2], $aE[3], $aE[4], $aE[5], $aE[6], $aE[7] _Edit($msg) Case $aS[0], $aS[1], $aS[2], $aS[3], $aS[4], $aS[5], $aS[6], $aS[7] _Stop($msg) Case $Skey _ToggleKeyHook() Case $Eall _Edit($msg, 1) Case $Sall _Stop($msg, 1) Case Else _Timer() EndSwitch WEnd Func _Edit($iD, $iFlag = 0) Local $IB, $KMchk, $sA If GUICtrlRead($Skey) = "Stop Key Monitoring" Then $KMchk = 1 _ToggleKeyHook() EndIf For $i = 0 To UBound($aE) - 1 If $aE[$i] = $iD Or $iFlag Then If $iFlag And $i = 0 Then $IB = InputBox("Edit all Skill timers", "Enter how many seconds.", $aStart[$i], Default, 140, 140, $aXY[0], $aXY[1], 0, $hGui) ElseIf Not $iFlag Then $IB = InputBox("Edit Skill " & $i + 1 & " timer", "Enter how many seconds.", $aStart[$i], Default, 140, 140, $aXY[0], $aXY[1], 0, $hGui) EndIf If StringIsAlNum($IB) And $IB > 0 Then $aProgress[$i][1] = 0 GUICtrlSetData($aProgress[$i][0], 100) $aStart[$i] = $IB GUICtrlSetData($aT[$i][0], $IB) EndIf If Not $iFlag Then If $KMchk Then _ToggleKeyHook() Return ElseIf (UBound($aE) - 1) = $i Then If $KMchk Then _ToggleKeyHook() Return EndIf EndIf Next EndFunc ;==>_Edit Func _Stop($iD, $iFlag = 0) For $i = 0 To UBound($aS) - 1 If $aS[$i] = $iD Or $iFlag Then $aProgress[$i][1] = 0 $aT[$i][1] = 0 GUICtrlSetData($aProgress[$i][0], 100) GUICtrlSetData($aT[$i][0], $aStart[$i]) GUICtrlSetBkColor($aT[$i][0], $GUI_BKCOLOR_TRANSPARENT) If $iFlag And (UBound($aS) - 1) <> $i Then ContinueLoop Return EndIf Next EndFunc ;==>_Stop Func _Timer() Local $TD For $i = 0 To UBound($aProgress, 1) - 1 If $aProgress[$i][1] Then $TD = $aStart[$i] - Floor(TimerDiff($aT[$i][1]) / $iWait) If $TD <> GUICtrlRead($aT[$i][0]) Then GUICtrlSetData($aT[$i][0], $TD) If TimerDiff($aProgress[$i][1]) >= ($aStart[$i] * $iWait / 100) And GUICtrlRead($aProgress[$i][0]) >= 1 Then GUICtrlSetData($aProgress[$i][0], GUICtrlRead($aProgress[$i][0]) - Round((TimerDiff($aProgress[$i][1]) / ($aStart[$i] * $iWait / 100)))) If $TD <= 0 Then GUICtrlSetData($aProgress[$i][0], 0) $aProgress[$i][1] = TimerInit() ElseIf GUICtrlRead($aProgress[$i][0]) < 1 Then GUICtrlSetData($aProgress[$i][0], 100) GUICtrlSetData($aT[$i][0], $aStart[$i]) $aT[$i][1] = 0 $aProgress[$i][1] = 0 EndIf EndIf Next EndFunc ;==>_Timer Func _ToggleKeyHook() If $hStub_KeyProc Then _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hStub_KeyProc) $hStub_KeyProc = 0 $hHook = 0 GUICtrlSetData($Skey, "Start Key Monitoring") Else $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam") $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), _WinAPI_GetModuleHandle(0)) GUICtrlSetData($Skey, "Stop Key Monitoring") EndIf EndFunc ;==>_ToggleKeyHook Func _KeyProc($nCode, $wParam, $lParam) Local $tKEYHOOKS, $iVK $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) If $wParam = $WM_KEYDOWN Then $iVK = DllStructGetData($tKEYHOOKS, "vkCode") Switch $iVK Case 49 To 56 If Not $aProgress[Chr($iVK - 1)][1] Then $aProgress[Chr($iVK - 1)][1] = TimerInit() $aT[Chr($iVK - 1)][1] = TimerInit() EndIf EndSwitch EndIf Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc ;==>_KeyProc Func _Save() For $i = 0 To UBound($aStart) - 1 IniWrite($Ini, "START", $i + 1, $aStart[$i]) Next IniWrite($Ini, "XY", "X", $aXY[0]) IniWrite($Ini, "XY", "Y", $aXY[1]) EndFunc ;==>_Save Func _Load() For $i = 0 To UBound($aStart) - 1 $aStart[$i] = IniRead($Ini, "START", $i + 1, 60) Next $aXY[0] = IniRead($Ini, "XY", "X", -1) $aXY[1] = IniRead($Ini, "XY", "Y", -1) EndFunc ;==>_Load Func WM_MOVE($hWnd, $iMsg, $iwParam, $ilParam) If BitAND(WinGetState($hWnd), 16) Then Return $GUI_RUNDEFMSG Local $WGP = WinGetPos($hWnd) $aXY[0] = $WGP[0] $aXY[1] = $WGP[1] Return $GUI_RUNDEFMSG EndFunc ;==>WM_MOVE Func OnAutoItExit() If $hStub_KeyProc Then _WinAPI_UnhookWindowsHookEx($hHook) If $hHook Then DllCallbackFree($hStub_KeyProc) EndFunc ;==>OnAutoItExitHmm it's a shame I don't or haven't played Guildwars. Cheers Edited August 22, 2009 by smashly Link to comment Share on other sites More sharing options...
RichE Posted August 22, 2009 Author Share Posted August 22, 2009 (edited) Your welcome, Had a further play with your code (I was bored.. lol) Added Edit timer functions and an Edit all timers button (the times are base as seconds). Added Stop timer buttons, also added a Stop all timers button (Basically it stops and resets the timer or timers) Progress Bar always start as a Full bar, just the Label tells how many seconds the timer is set for or left to go. Added Start/Stop Monitoring keys button. Added Save/load X & Y Gui position and Timer values (Saves on exit, Loads on start of Gui) So if you had trouble wrapping your mind on my non commented butchered efforts before, then it's even worse now.. lolexpandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> Opt('MustDeclareVars', 1) Global $Ini = @ScriptDir & "\SkillTimer.ini", $iWait = 1000 Global $hGui, $aXY[2], $aProgress[8][2], $aStart[8], $aT[8][2], $aE[8], $aS[8], $Eall, $Sall, $Skey, $msg Global $hStub_KeyProc, $hHook _Load() $hGui = GUICreate("Skill timer", 295, 280, $aXY[0], $aXY[1], -1, $WS_EX_TOPMOST) For $i = 0 To UBound($aProgress, 1) - 1 GUICtrlCreateLabel("Skill " & $i + 1, 10, ($i * 30) + 10, 35, 20, BitOR($SS_CENTER, $BS_CENTER)) $aProgress[$i][0] = GUICtrlCreateProgress(50, ($i * 30) + 10, 150, 20, $PBS_SMOOTH) GUICtrlSetData(-1, 100) $aT[$i][0] = GUICtrlCreateLabel($aStart[$i], 205, ($i * 30) + 10, 30, 20, BitOR($SS_CENTER, $BS_CENTER)) $aE[$i] = GUICtrlCreateButton("E", 240, ($i * 30) + 10, 20, 20) GUICtrlSetTip(-1, "Click E button to edit the timer for skill " & $i + 1) $aS[$i] = GUICtrlCreateButton("S", 265, ($i * 30) + 10, 20, 20) GUICtrlSetTip(-1, "Click S button to stop the timer for skill " & $i + 1) Next $Skey = GUICtrlCreateButton("Start Key Monitoring", 10, ($i * 30) + 10, 105, 20) $Eall = GUICtrlCreateButton("Edit all timers", 125, ($i * 30) + 10, 75, 20) $Sall = GUICtrlCreateButton("Stop all timers", 210, ($i * 30) + 10, 75, 20) GUISetState(@SW_SHOW, $hGui) _ToggleKeyHook() GUIRegisterMsg($WM_MOVE, "WM_MOVE") While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE _Save() Exit Case $aE[0], $aE[1], $aE[2], $aE[3], $aE[4], $aE[5], $aE[6], $aE[7] _Edit($msg) Case $aS[0], $aS[1], $aS[2], $aS[3], $aS[4], $aS[5], $aS[6], $aS[7] _Stop($msg) Case $Skey _ToggleKeyHook() Case $Eall _Edit($msg, 1) Case $Sall _Stop($msg, 1) Case Else _Timer() EndSwitch WEnd Func _Edit($iD, $iFlag = 0) Local $IB, $KMchk, $sA If GUICtrlRead($Skey) = "Stop Key Monitoring" Then $KMchk = 1 _ToggleKeyHook() EndIf For $i = 0 To UBound($aE) - 1 If $aE[$i] = $iD Or $iFlag Then If $iFlag And $i = 0 Then $IB = InputBox("Edit all Skill timers", "Enter how many seconds.", $aStart[$i], Default, 140, 140, $aXY[0], $aXY[1], 0, $hGui) ElseIf Not $iFlag Then $IB = InputBox("Edit Skill " & $i + 1 & " timer", "Enter how many seconds.", $aStart[$i], Default, 140, 140, $aXY[0], $aXY[1], 0, $hGui) EndIf If StringIsAlNum($IB) And $IB > 0 Then $aProgress[$i][1] = 0 GUICtrlSetData($aProgress[$i][0], 100) $aStart[$i] = $IB GUICtrlSetData($aT[$i][0], $IB) EndIf If Not $iFlag Then If $KMchk Then _ToggleKeyHook() Return ElseIf (UBound($aE) - 1) = $i Then If $KMchk Then _ToggleKeyHook() Return EndIf EndIf Next EndFunc ;==>_Edit Func _Stop($iD, $iFlag = 0) For $i = 0 To UBound($aS) - 1 If $aS[$i] = $iD Or $iFlag Then $aProgress[$i][1] = 0 $aT[$i][1] = 0 GUICtrlSetData($aProgress[$i][0], 100) GUICtrlSetData($aT[$i][0], $aStart[$i]) GUICtrlSetBkColor($aT[$i][0], $GUI_BKCOLOR_TRANSPARENT) If $iFlag And (UBound($aS) - 1) <> $i Then ContinueLoop Return EndIf Next EndFunc ;==>_Stop Func _Timer() Local $TD For $i = 0 To UBound($aProgress, 1) - 1 If $aProgress[$i][1] Then $TD = $aStart[$i] - Floor(TimerDiff($aT[$i][1]) / $iWait) If $TD <> GUICtrlRead($aT[$i][0]) Then GUICtrlSetData($aT[$i][0], $TD) If TimerDiff($aProgress[$i][1]) >= ($aStart[$i] * $iWait / 100) And GUICtrlRead($aProgress[$i][0]) >= 1 Then GUICtrlSetData($aProgress[$i][0], GUICtrlRead($aProgress[$i][0]) - Round((TimerDiff($aProgress[$i][1]) / ($aStart[$i] * $iWait / 100)))) If $TD <= 0 Then GUICtrlSetData($aProgress[$i][0], 0) $aProgress[$i][1] = TimerInit() ElseIf GUICtrlRead($aProgress[$i][0]) < 1 Then GUICtrlSetData($aProgress[$i][0], 100) GUICtrlSetData($aT[$i][0], $aStart[$i]) $aT[$i][1] = 0 $aProgress[$i][1] = 0 EndIf EndIf Next EndFunc ;==>_Timer Func _ToggleKeyHook() If $hStub_KeyProc Then _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hStub_KeyProc) $hStub_KeyProc = 0 $hHook = 0 GUICtrlSetData($Skey, "Start Key Monitoring") Else $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam") $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), _WinAPI_GetModuleHandle(0)) GUICtrlSetData($Skey, "Stop Key Monitoring") EndIf EndFunc ;==>_ToggleKeyHook Func _KeyProc($nCode, $wParam, $lParam) Local $tKEYHOOKS, $iVK $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) If $wParam = $WM_KEYDOWN Then $iVK = DllStructGetData($tKEYHOOKS, "vkCode") Switch $iVK Case 49 To 56 If Not $aProgress[Chr($iVK - 1)][1] Then $aProgress[Chr($iVK - 1)][1] = TimerInit() $aT[Chr($iVK - 1)][1] = TimerInit() EndIf EndSwitch EndIf Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc ;==>_KeyProc Func _Save() For $i = 0 To UBound($aStart) - 1 IniWrite($Ini, "START", $i + 1, $aStart[$i]) Next IniWrite($Ini, "XY", "X", $aXY[0]) IniWrite($Ini, "XY", "Y", $aXY[1]) EndFunc ;==>_Save Func _Load() For $i = 0 To UBound($aStart) - 1 $aStart[$i] = IniRead($Ini, "START", $i + 1, 60) Next $aXY[0] = IniRead($Ini, "XY", "X", -1) $aXY[1] = IniRead($Ini, "XY", "Y", -1) EndFunc ;==>_Load Func WM_MOVE($hWnd, $iMsg, $iwParam, $ilParam) If BitAND(WinGetState($hWnd), 16) Then Return $GUI_RUNDEFMSG Local $WGP = WinGetPos($hWnd) $aXY[0] = $WGP[0] $aXY[1] = $WGP[1] Return $GUI_RUNDEFMSG EndFunc ;==>WM_MOVE Func OnAutoItExit() If $hStub_KeyProc Then _WinAPI_UnhookWindowsHookEx($hHook) If $hHook Then DllCallbackFree($hStub_KeyProc) EndFunc ;==>OnAutoItExitHmm it's a shame I don't or haven't played Guildwars. Cheers Wow, thanks mate your an absolute star, you've done everything I wanted to do with it, pitty there's no karma reward system on the forum, you'd get uber karma from me . oh btw, can you PM me your real name so I can put it onto the "Written by...", as I think other ppl will like this as well, thats if you don't mind..? Edited August 22, 2009 by l15ard RichE [font="'Arial Narrow';"]Current projects[/font] [font="'Arial Narrow';"]are on my site [/font]Sellostring Link to comment Share on other sites More sharing options...
smashly Posted August 22, 2009 Share Posted August 22, 2009 (edited) Your welcome and glad you like it, Feel free to put your own name on it and treat it as your own code. If you want to put my name then you should put it as ; Written by: l15ard ; Modified by: smashly After all it's your idea and code that's at the core of it. I mainly did it because I was bored of my own projects and I needed something to do while waiting for a game to dl (Wolfenstien ... w00t)..lol Sorry the codes not commented to make it easier to understand. Feel free to ask questions if your having trouble understanding parts of it and I'll do my best to explain. The reason I put all the controls and stuff in array's and loops was so the code would be a little shorter. If I had written each control and set each controls states and checks the code would have been at least 4x+ the length it is now. Hard to believe there's 40+ controls on that little gui >_< Cheers Edited August 22, 2009 by smashly Link to comment Share on other sites More sharing options...
RichE Posted August 22, 2009 Author Share Posted August 22, 2009 Your welcome and glad you like it,Feel free to put your own name on it and treat it as your own code.If you want to put my name then you should put it as ; Written by: l15ard; Modified by: smashlyAfter all it's your idea and code that's at the core of it.I mainly did it because I was bored of my own projects and I needed something to do while waiting for a game to dl (Wolfenstien ... w00t)..lolSorry the codes not commented to make it easier to understand.Feel free to ask questions if your having trouble understanding parts of it and I'll do my best to explain.The reason I put all the controls and stuff in array's and loops was so the code would be a little shorter.If I had written each control and set each controls states and checks the code would have been at least 4x+ the length it is now.Hard to believe there's 40+ controls on that little gui CheersWell, I've compiled it and posted it up on my site (link in my sig), I've used an inno installer, and mentioned your name in the license section, I changed the gui abit, as you'll see by the screenshot of the app, thanks again. RichE [font="'Arial Narrow';"]Current projects[/font] [font="'Arial Narrow';"]are on my site [/font]Sellostring Link to comment Share on other sites More sharing options...
royco Posted September 6, 2009 Share Posted September 6, 2009 (edited) maybe you can take it further when i press 1 it start loop pressing 1 2 pressing 2 in loop and make it 1 2 3 to 0 all the number on keyboard also lets say i wanted to stop after hour or so thanks Edited October 16, 2009 by royco Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now