FireFox Posted December 19, 2008 Share Posted December 19, 2008 (edited) Hi,Im updating Counter v1.2, but there is always problems when I want to add something in; here the Function _AddCount doesn't detect that youve checked checkbox...Last time I had to do same thing for Combo and add it to While but if I do that for it I will have big while and script will be long for count something...CODE#include <DllCallBack.au3> #include <GuiConstants.au3> #include <WindowsConstants.au3> #include <ComboConstants.au3> #include <GuiButton.au3> #include <Constants.au3> ;~ #include <Misc.au3> #Region Opt Opt("TrayMenuMode", 1) Opt("TrayOnEventMode", 1) Opt("GuiOnEventMode", 1) Opt("TrayIconHide", 1) #EndRegion Opt #Region Tray TraySetIcon("Shell32.dll", 27) TrayCreateItem("Counter...") TrayItemSetOnEvent(-1, "_Count") $MSU = TrayCreateMenu("Start-up") $SUON = TrayCreateItem("ON", $MSU) TrayItemSetOnEvent(-1, "_SUON") $SUOFF = TrayCreateItem("OFF", $MSU) TrayItemSetOnEvent(-1, "_SUOFF") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "_Exit") TraySetOnEvent(-13, "_SHOW") #EndRegion Tray #Region Hook Keyboard --------------------------- ;~ Global Const $WH_KEYBOARD_LL = 13 Global $hHook, $pStub_KeyProc, $GUI Global $KeyCount, $TotalKey = "None", $Countwhat, $CPUCalc Global $pStub_KeyProc = _DllCallBack("_KeyProc", "int;ptr;ptr") Global $hmod = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0) Global $hHook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_KEYBOARD_LL, "ptr", $pStub_KeyProc, "hwnd", $hmod[0], "dword", 0) $hButton = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:Button;Instance:1]") Local $IDLETIME, $KERNELTIME, $USERTIME Local $StartIdle, $StartKernel, $StartUser Local $EndIdle, $EndKernel, $EndUser $IDLETIME = DllStructCreate("dword;dword") $KERNELTIME = DllStructCreate("dword;dword") $USERTIME = DllStructCreate("dword;dword") #EndRegion Hook Keyboard --------------------------- #Region Variables ------------------------------- ;~ $Record = FileRead(@TempDir & "\KeyCounter.txt") Local $GUIlblDateStarted, $GUIlblKeysPressed, _ $GUIlblProcess, $GUIcboKeyMouse, $GUIlblCPU, _ $GUIlblMEM, $GUIlblMousedist, $GUIlblTimeStarted, _ $GUIlblStart, $lastdistance, $StartClick, $AddCount Local $Date = @MDAY & "/" & @MON & "/" & @YEAR _ReduceMemory(@ScriptName) Dim $last_pos[2] = [0, 0] $Init = TimerInit() $pl = ProcessList() $lastnb = $pl[0][0] #EndRegion Variables ------------------------------- #Region Count ------------------------------------------------------------------------------------- $Count = GUICreate("Mouse'n key Counter <d3montools> " & $Date, 400, 95, -1, -1, -1, BitOR($WS_EX_APPWINDOW, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetOnEvent($GUI_EVENT_CLOSE, "_CLOSE2") $Ct1 = GUICtrlCreateCheckbox("Time since", 5, 5, 100, 17) $Ct2 = GUICtrlCreateCheckbox("Keys pressed", 5, 25, 100, 17) $Ct3 = GUICtrlCreateCheckbox("Mouse dist", 5, 45, 100, 17) $Ct4 = GUICtrlCreateCheckbox("Total process", 120, 5, 100, 17) $Ct5 = GUICtrlCreateCheckbox("Get CPU Usage", 120, 25, 100, 17) $Ct6 = GUICtrlCreateCheckbox("Get MEM Usage", 120, 45, 100, 17) $Ct7 = GUICtrlCreateCheckbox("Start Click", 245, 5, 100, 17) ;~ $Ct8 = GUICtrlCreateCheckbox("Add other count", 245, 25, 100, 17) GUICtrlCreateButton("Count it !", 140, 70, 100, 20) GUICtrlSetOnEvent(-1, "_AddCount") GUISetState(@SW_HIDE) Func _AddCount() Local $GUICTRL GUIDelete($GUI) _GUICreate() If BitAND(GUICtrlRead($Ct1), $GUI_CHECKED) Then GUICtrlCreateLabel("Count since :", 5, 5, 70, 15) $GUIlblTimeStarted = GUICtrlCreateLabel("0 sec", 75, 5, 150, 15) MsgBox(64, "", "");This msgbox doesnt work if you check $Ct1 $GUICTRL = 1 EndIf If BitAND(GUICtrlRead($Ct2), $GUI_CHECKED) Then If $GUICTRL = 1 Then GUICtrlCreateLabel("Count key of :", 170, 5) $GUIcboKeyMouse = GUICtrlCreateCombo("All", 240, 2, 80, 17, $CBS_DROPDOWNLIST) GUICtrlSetData(-1, "Mouse|Keyboard", "All") GUICtrlCreateLabel("Keys pressed :", 5, 29, 100, 15) $GUIlblKeysPressed = GUICtrlCreateLabel("0", 80, 29, 100, 15) $GUICTRL = 2 ElseIf $GUICTRL = 0 Then GUICtrlCreateLabel("Count key of :", 170, 5) $GUIcboKeyMouse = GUICtrlCreateCombo("All", 240, 2, 80, 17, $CBS_DROPDOWNLIST) GUICtrlSetData(-1, "Mouse|Keyboard", "All") GUICtrlCreateLabel("Keys pressed :", 5, 5, 100, 15) $GUIlblKeysPressed = GUICtrlCreateLabel("0", 80, 5, 100, 15) $GUICTRL = 1 EndIf EndIf If BitAND(GUICtrlRead($Ct3), $GUI_CHECKED) Then If $GUICTRL = 2 Then GUICtrlCreateLabel("Mouse dist :", 5, 29) $GUIlblMousedist = GUICtrlCreateLabel("0 pixel", 70, 29, 100) $GUICTRL = 3 ElseIf $GUICTRL = 1 Then GUICtrlCreateLabel("Mouse dist :", 170, 5) $GUIlblMousedist = GUICtrlCreateLabel("0 pixel", 240, 5, 100) $GUICTRL = 2 ElseIf $GUICTRL = 0 Then GUICtrlCreateLabel("Mouse dist :", 5, 5) $GUIlblMousedist = GUICtrlCreateLabel("0 pixel", 75, 5, 100) $GUICTRL = 1 EndIf EndIf If BitAND(GUICtrlRead($Ct4), $GUI_CHECKED) Then If $GUICTRL = 3 Then GUICtrlCreateLabel("Total Process :", 170, 29, 100, 15) $GUIlblProcess = GUICtrlCreateLabel("0", 240, 29, 100, 15) $GUICTRL = 4 ElseIf $GUICTRL = 2 Then GUICtrlCreateLabel("Total Process :", 5, 29, 100, 15) $GUIlblProcess = GUICtrlCreateLabel("0", 80, 29, 100, 15) $GUICTRL = 3 ElseIf $GUICTRL = 1 Then GUICtrlCreateLabel("Total Process :", 170, 5, 100, 15) $GUIlblProcess = GUICtrlCreateLabel("0", 240, 5, 100, 15) $GUICTRL = 2 ElseIf $GUICTRL = 0 Then GUICtrlCreateLabel("Total Process :", 5, 5, 100, 15) $GUIlblProcess = GUICtrlCreateLabel("0", 80, 5, 100, 15) $GUICTRL = 1 EndIf EndIf If BitAND(GUICtrlRead($Ct5), $GUI_CHECKED) Then If $GUICTRL = 4 Then $GUIlblCPU = GUICtrlCreateLabel("CPU : 0%", 5, 52, 100, 15) $GUICTRL = 5 ElseIf $GUICTRL = 3 Then $GUIlblCPU = GUICtrlCreateLabel("CPU : 0%", 170, 29, 100, 15) $GUICTRL = 4 ElseIf $GUICTRL = 2 Then $GUIlblCPU = GUICtrlCreateLabel("CPU : 0%", 5, 29, 100, 15) $GUICTRL = 3 ElseIf $GUICTRL = 1 Then $GUIlblCPU = GUICtrlCreateLabel("CPU : 0%", 170, 5, 100, 15) $GUICTRL = 2 ElseIf $GUICTRL = 0 Then $GUIlblCPU = GUICtrlCreateLabel("CPU : 0%", 5, 5, 100, 15) $GUICTRL = 1 EndIf EndIf If BitAND(GUICtrlRead($Ct6), $GUI_CHECKED) Then If $GUICTRL = 5 Then $GUIlblMEM = GUICtrlCreateLabel("MEM : 0%", 240, 52, 100, 15) $GUICTRL = 6 ElseIf $GUICTRL = 4 Then $GUIlblMEM = GUICtrlCreateLabel("MEM : 0%", 5, 52, 100, 15) $GUICTRL = 5 ElseIf $GUICTRL = 3 Then $GUIlblMEM = GUICtrlCreateLabel("MEM : 0%", 170, 29, 100, 15) $GUICTRL = 4 ElseIf $GUICTRL = 2 Then $GUIlblMEM = GUICtrlCreateLabel("MEM : 0%", 5, 29, 100, 15) $GUICTRL = 3 ElseIf $GUICTRL = 1 Then $GUIlblMEM = GUICtrlCreateLabel("MEM : 0%", 170, 5, 100, 15) $GUICTRL = 2 ElseIf $GUICTRL = 0 Then $GUIlblMEM = GUICtrlCreateLabel("MEM : 0%", 5, 5, 100, 15) $GUICTRL = 1 EndIf EndIf If BitAND(GUICtrlRead($Ct7), $GUI_CHECKED) Then If $GUICTRL = 6 Then $GUIlblStart = GUICtrlCreateLabel("Start Click : 0", 240, 52, 100, 15) $GUICTRL = 7 ElseIf $GUICTRL = 5 Then $GUIlblStart = GUICtrlCreateLabel("Start Click : 0", 240, 52, 100, 15) $GUICTRL = 6 ElseIf $GUICTRL = 4 Then $GUIlblStart = GUICtrlCreateLabel("Start Click : 0", 5, 52, 100, 15) $GUICTRL = 5 ElseIf $GUICTRL = 3 Then $GUIlblStart = GUICtrlCreateLabel("Start Click : 0", 170, 29, 100, 15) $GUICTRL = 4 ElseIf $GUICTRL = 2 Then $GUIlblStart = GUICtrlCreateLabel("Start Click : 0", 5, 29, 100, 15) $GUICTRL = 3 ElseIf $GUICTRL = 1 Then $GUIlblStart = GUICtrlCreateLabel("Start Click : 0", 170, 5, 100, 15) $GUICTRL = 2 ElseIf $GUICTRL = 0 Then $GUIlblStart = GUICtrlCreateLabel("Start Click : 0", 5, 5, 100, 15) $GUICTRL = 1 EndIf EndIf EndFunc ;==>_AddCount ;~ GUICtrlCreateLabel("Record :", 195, 27) ;~ $GUIlblRecord = GUICtrlCreateLabel(FileRead(@TempDir & "\KeyCounter.txt"), 245, 27, 100) GUISetState(@SW_HIDE, $Count) #EndRegion Count ------------------------------------------------------------------------------------- #Region GUI --------------------------------------------------------------------------------------- Func _GUICreate() $GUI = GUICreate("Mouse'n key Counter <d3montools> " & $Date, 330, 70, -1, -1, -1, BitOR($WS_EX_APPWINDOW, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetOnEvent($GUI_EVENT_CLOSE, "_CLOSE") ;~ GUISetState(@SW_HIDE, $GUI) EndFunc ;==>_GUICreate Func _GUICount() EndFunc ;==>_GUICount #EndRegion GUI --------------------------------------------------------------------------------------- #Region GUI STATE ---------------------------------------------------------------------------------- Func _CLOSE() GUISetState(@SW_HIDE, $GUI) _ReduceMemory(@ScriptName) EndFunc ;==>_CLOSE Func _SHOW() GUISetState(@SW_SHOW, $GUI) _ReduceMemory(@ScriptName) EndFunc ;==>_SHOW Func _Count() GUISetState(@SW_SHOW, $Count) _ReduceMemory(@ScriptName) EndFunc ;==>_Count Func _CLOSE2() GUISetState(@SW_HIDE, $Count) _ReduceMemory(@ScriptName) EndFunc ;==>_CLOSE2 #EndRegion GUI STATE ---------------------------------------------------------------------------------- #Region Keyboard Key ------------------------------------------------------------------------------ Func EvaluateKey($keycode) If (($keycode > 22) And ($keycode < 91)) _ Or (($keycode > 47) And ($keycode < 58)) Then GUICtrlSetData($GUIlblKeysPressed, $TotalKey + 1) Global $TotalKey = GUICtrlRead($GUIlblKeysPressed) Else GUICtrlSetData($GUIlblKeysPressed, $TotalKey + 1) Global $TotalKey = GUICtrlRead($GUIlblKeysPressed) EndIf EndFunc ;==>EvaluateKey Func _KeyProc($nCode, $wParam, $lParam) Local $ret, $KEYHOOKSTRUCT If $Countwhat = 0 Or $Countwhat = 2 Then If $nCode < 0 Then $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hHook[0], _ "int", $nCode, "ptr", $wParam, "ptr", $lParam) Return $ret[0] EndIf If $wParam = 256 Then $KEYHOOKSTRUCT = DllStructCreate("dword;dword;dword;dword;ptr", $lParam) EvaluateKey(DllStructGetData($KEYHOOKSTRUCT, 1)) EndIf $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hHook[0], _ "int", $nCode, "ptr", $wParam, "ptr", $lParam) Return $ret[0] EndIf EndFunc ;==>_KeyProc #EndRegion Keyboard Key ------------------------------------------------------------------------------ #Region Start-up ---------------------------------------------------------------------------------- RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "KeyCounter") If @error Then TrayItemSetState($SUOFF, $TRAY_CHECKED) Else TrayItemSetState($SUON, $TRAY_CHECKED) EndIf Func _SUON() RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "KeyCounter", "REG_SZ", @ScriptFullPath) TrayItemSetState($SUOFF, $TRAY_UNCHECKED) TrayItemSetState($SUON, $TRAY_CHECKED) EndFunc ;==>_SUON Func _SUOFF() RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "KeyCounter") TrayItemSetState($SUOFF, $TRAY_CHECKED) TrayItemSetState($SUON, $TRAY_UNCHECKED) EndFunc ;==>_SUOFF #EndRegion Start-up ---------------------------------------------------------------------------------- Func _Exit() ;~ MsgBox(64,"",$Record&" | "&$TotalKey) ;~ If $Record < $TotalKey Then ;~ MsgBox(64,"","New record saved") ;~ FileDelete(@TempDir & "\KeyCounter.txt") ;~ FileWrite(@TempDir & "\KeyCounter.txt", $TotalKey) ;~ EndIf DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hHook[0]) Exit EndFunc ;==>_Exit #Region ReduceMemory------------------------------------------------------------------------------- ;=============================================================================== ; Function Name: _ReduceMemory ; Author(s): jftuga ;=============================================================================== Func _ReduceMemory($i_PID = -1) If $i_PID <> -1 Then Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID) Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0]) DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0]) Else Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1) EndIf Return $ai_Return[0] EndFunc ;==>_ReduceMemory #EndRegion ReduceMemory------------------------------------------------------------------------------- #Region CPU---------------------------------------------------------------------------------------- ;=============================================================================== ; Function Name: _GetSysTime / _CPUCalc ; Author(s): rasim ;=============================================================================== Func _GetSysTime(ByRef $sIdle, ByRef $sKernel, ByRef $sUser) DllCall("kernel32.dll", "int", "GetSystemTimes", "ptr", DllStructGetPtr($IDLETIME), _ "ptr", DllStructGetPtr($KERNELTIME), _ "ptr", DllStructGetPtr($USERTIME)) $sIdle = DllStructGetData($IDLETIME, 1) $sKernel = DllStructGetData($KERNELTIME, 1) $sUser = DllStructGetData($USERTIME, 1) EndFunc ;==>_GetSysTime Func _CPUCalc() Local $iSystemTime, $iTotal, $iCalcIdle, $iCalcKernel, $iCalcUser $iCalcIdle = ($EndIdle - $StartIdle) $iCalcKernel = ($EndKernel - $StartKernel) $iCalcUser = ($EndUser - $StartUser) $iSystemTime = ($iCalcKernel + $iCalcUser) $iTotal = Int(($iSystemTime - $iCalcIdle) * (100 / $iSystemTime)) & "%" Global $CPUCalc = $iTotal EndFunc ;==>_CPUCalc #EndRegion CPU---------------------------------------------------------------------------------------- #Region _IsPressed--------------------------------------------------------------------------------- ;=============================================================================== ; Function Name: _IsPressed ; Author(s): FireFox (Thanks to original _IsPressed) ;=============================================================================== Func _IsPressed($HexKey, $vDLL = 'user32.dll') $sHexKey = StringSplit($HexKey, "|", 1) For $nb = 1 To UBound($sHexKey) - 1 $a_R = DllCall($vDLL, "int", "GetAsyncKeyState", "int", '0x' & $sHexKey[$nb]) If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1 Next Return 0 EndFunc ;==>_IsPressed #EndRegion _IsPressed--------------------------------------------------------------------------------- Opt("TrayIconHide", 0) While 1 Sleep(100) #Region Key pressed ------------------------------------------------------------------------------- Switch GUICtrlRead($GUIcboKeyMouse) Case "All" $Countwhat = 0 Case "Mouse" $Countwhat = 1 Case "Keyboard" $Countwhat = 2 EndSwitch If $AddCount = 1 Then Select Case GUICtrlRead($Ct1) = $GUI_CHECKED MsgBox(64, "", "") EndSelect EndIf If $Countwhat = 1 Or $Countwhat = 0 Then If _IsPressed("01|02|03|04|05|06") Then Do ;Nothing Until Not _IsPressed("01|02|03|04|05|06") GUICtrlSetData($GUIlblKeysPressed, $TotalKey + 1) Global $TotalKey = GUICtrlRead($GUIlblKeysPressed) EndIf EndIf #EndRegion Key pressed ------------------------------------------------------------------------------- #Region Start Button Click If BitAND(_GUICtrlButton_GetState($hButton), $BST_PUSHED) Then GUICtrlSetData($GUIlblStart, "Start Clicks : " & $StartClick + 1) Global $TotalClick = GUICtrlRead($GUIlblStart) EndIf #EndRegion Start Button Click #Region Process ------------------------------------------------------------------------------- $wpl = ProcessList() $diff = $wpl[0][0] - $lastnb If $diff >= 0 Then $nb = $wpl[0][0] + $diff $lastnb = $nb EndIf GUICtrlSetData($GUIlblProcess, $lastnb) #EndRegion Process ------------------------------------------------------------------------------- #Region CPU/MEM ------------------------------------------------------------------------------- _GetSysTime($EndIdle, $EndKernel, $EndUser) _CPUCalc();-------------------------------- _GetSysTime($StartIdle, $StartKernel, $StartUser) GUICtrlSetData($GUIlblCPU, "CPU : " & $CPUCalc) $Stats = MemGetStats() GUICtrlSetData($GUIlblMEM, "Memory : " & $Stats[0] & "%") #EndRegion CPU/MEM ------------------------------------------------------------------------------- #Region Mouse distance ------------------------------------------------------------------------ $current_pos = MouseGetPos() $distance = Sqrt(($current_pos[0] - $last_pos[0]) ^ 2 + ($current_pos[1] - $last_pos[1]) ^ 2) $mousedist = $distance + $lastdistance $lastdistance = $mousedist $last_pos = $current_pos $mousesplit = StringSplit($mousedist, ".") If Not @error Then $distance = $mousesplit[1] GUICtrlSetData($GUIlblMousedist, $distance & " pixels") Else $distance = $mousedist GUICtrlSetData($GUIlblMousedist, $distance & " pixels") EndIf #EndRegion Mouse distance ------------------------------------------------------------------------ ;~ If $TotalKey > $Record Then ;~ GUICtrlSetData($GUIlblRecord, $TotalKey) ;~ EndIf $diff = StringLeft(TimerDiff($Init) * 0.001, 5) GUICtrlSetData($GUIlblTimeStarted, $diff & " sec") TraySetToolTip("Counter <d3montools>" _ & @CRLF & "Keys pressed : " & $TotalKey _ & @CRLF & "Mouse dist : " & $distance _ & @CRLF & "Total process : " & $lastnb _ & @CRLF & "CPU Usage : " & $CPUCalc _ & @CRLF & "MEM Usage : " & $Stats[0] & "%") WEndDllCallBack.au3 : DllCallBackNote : Updated Script with new _IsPressed function by me thanks to original _IsPressed of course and Startbutton click by rasim Edited December 19, 2008 by FireFox Please use codebox tags with large scripts over 50 lines Link to comment Share on other sites More sharing options...
rasim Posted December 19, 2008 Share Posted December 19, 2008 (edited) @FireFoxCan you make a small example to represent the problem? Edit:Maybe this will helps:If BitAND(GUICtrlRead($cCheckbox), $GUI_CHECKED) Then ... Edited December 19, 2008 by rasim Link to comment Share on other sites More sharing options...
FireFox Posted December 19, 2008 Author Share Posted December 19, 2008 @rasim Thanks for help but this doesnt work... Example : Start counter, Go to tray Icon and click on Counter... Then Check the First CheckBox and Click on "Count it !" Normaly Msgbox would show but i doesnt work... Msgbox Line 85 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted December 19, 2008 Moderators Share Posted December 19, 2008 @rasimThanks for help but this doesnt work...Example :Start counter,Go to tray Icon and click on Counter...Then Check the First CheckBox and Click on "Count it !"Normaly Msgbox would show but i doesnt work...Msgbox Line 85I doubt anyone is going to debug 480+ lines of code for you, or if they are going to go out of their way to find dllcallback.au3 (when we have a native dllcallback already built in). There is still another error I got on top of it all.A suggestion that rasim made, I'll iterate myself. Don't post a huge script, write a re-creation script that demonstrates your issues in less than 50 lines of code and don't make others hunt down non-standard include files to make it work. Also state what version of AutoIt you are using as well, many of us will not be using the same versions. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
FireFox Posted December 19, 2008 Author Share Posted December 19, 2008 @SmOke_N Thanks for your suggestion but I've tried to make little example and it work so I think its another thing make it doesnt work... Link to comment Share on other sites More sharing options...
rasim Posted December 20, 2008 Share Posted December 20, 2008 @SmOke_NThanks for your suggestion but I've tried to make little example and it work so I think its another thing make it doesnt work...Debug your script step by step, for instance use ConsoleWrite or MsgBox functions after questionable script part. Anyway, I don't see other ways 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